Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 81 - 2609_Logicode
P. 81

    PROMPT BOX
                     A Prompt Box asks the user to input a value. If the user clicks OK, it returns the entered value;

                     if Cancel is clicked, it returns null. The prompt() method is used to display the prompt, with the
                     input value stored in a variable. The prompt text is specified as a string within the parentheses.

                        Code
                          8      Create a web page to demonstrate the use of Prompt Box in JavaScript.

                     <!DOCTYPE HTML>
                     <HTML>
                     <HEAD>

                     <TITLE>Prompt Box</TITLE>
                     </HEAD>
                     <BODY>
                     <SCRIPT>

                     {
                     var userName = prompt("Please enter your name:")
                     document.write("Hello, " + userName + "!")

                     }
                     </SCRIPT>
                     </BODY>
                     </HTML>
                     The output of the preceding HTML code is as follows:

                         Design a login form in HTML with Username and Password fields and use JavaScript to
                         display an alert if any field is left empty when the user clicks the Login button.

                                                                                               JavaScript for Beginners  79

| 76 77 78 79 80 81 82 83 84 85 86 |