Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 117 - CodePilot V5.0 C8
P. 117

    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:

                                                                                                21 st   #Technology Literacy
                          EXPERIENTIAL LEARNING                                                Century   #Information Literacy
                                                                                               Skills
                       Create a school login page using JavaScript that prompts the user to enter a username & password
                       and displays a message based on the input.

                                                                                                                      115
                                                                                                JavaScript for Beginners

| 112 113 114 115 116 117 118 119 120 121 122 |