Learn HTML,CSS, Python etc from the foundation

Thursday, February 7, 2019

STEP BY STEP GUIDE ON HOW TO CREATE CONFIRM AND PROMPT BOX USING JAVASCRIPT

No comments :


Hi, welcome to our fourth lesson on JavaScript. In this lesson, I will unveil to you a practical way you can create a confirm box and as well prompt box using JavaScript. Perhaps you may have seen something popping up whenever you visit a website, prompting you to take a certain action. Well, most of those things (like confirm box, prompt box, etc.) were simply programmed using JavaScript. Without wasting much of your time, I will take you by hand and guide you through various steps that are necessary to enable you to create a confirm box and a prompt box. If you’re interested, then read on.

       I.            CONFIRM BOX
Confirm box, just as the name suggests is a form of a dialog box that's usually pop up on the window/screen of your device, demanding the user to validate or reject an action by simply clicking the “OK” or “Cancel” button on the box. Let us consider an example to drive home the above point.
Open your text editor. I believe by now you’ve known JavaScript template structure by heart. Nevertheless, I will write everything in full once more.

<!DOCTYPE HTML>
<HTML>
            <HEAD>
                        <TITLE>Template</TITLE>
            </HEAD>
           
            <BODY>
                        <SCRIPT LANGUAGE = "Javascript">
                                    confirm("OK or Cancel")

                        </SCRIPT>

            </BODY>
</HTML>

IT WILL LOOK LIKE THIS IN YOUR TEXT EDITOR

SAVE AND OPEN IT, IT WILL LOOK LIKE THIS



     II.            PROMPT BOX
Prompt box works almost the same way as the confirm box. The only slight difference here is that the prompt has two parts usually enveloped with round brackets. The first part is often referred to as the main, while the second part is sometimes called the tail. The tail usually contains some default text(s). This prompts a user to enter some texts in the text box, and after the user is done and clicked “OK”, then the program will execute some actions.
Let us look at an example.
Change the confirm box in the example above and add the following.
Prompt (“Today is What?”, “Monday”)

IT WILL LOOK LIKE THIS IN YOUR TEXT EDITOR



SAVE AND OPEN IT, IT WILL LOOK LIKE THIS





WRAPPING UP
In our next lesson, we are going to be looking at JavaScript placement in HTML document. Before then, keep practising.


No comments :

Post a Comment