Page 353 - Webapplication11_C11_Flipbook
P. 353

</SCRIPT>
                   </BODY> </HTML>
                 Output of the above code is as follows:

















                 When you click on the “OK” button, with the message “this page says”. Then a new window opens with the message
                 “Learning JavaScript Alert”.














                 The prompt( ) Method

                 Ð ÐPrompts the user to enter a value. It has two buttons, one for ‘OK’ and one for ‘Cancel’.
                 Ð ÐThis method takes two parameters. First argument accepts a value in the form of a question that will be shown in
                   the dialogue box in which the user’s input is required. The second argument is optional and contains the question’s
                   default answer. If the user does not provide a value, the value of the second argument will be used as the answer.
                   If the value is entered by the user, the second value takes precedence over the default value.

                 Ð ÐWhen the user enters a value, the OK button is pressed to confirm input.
                 Ð ÐAfter hitting the OK button, the prompt( ) method returns the value. It returns the input value if it is entered;
                   otherwise, if the user clicks the Cancel button, it returns null.
                 Example:

                   <HTML>
                   <HEAD>
                   <TITLE>Using prompt box</TITLE>

                   </HEAD>
                   <BODY>
                   <script type = "text/javascript">
                   var age=prompt("Enter Age", "18");
                   if (age == null || age == " ") // If user clicks the Cancel button

                   {
                   alert("No input received");
                   }
                   else if(age < 18)

                                                                                                  JavaScript Part 1  351
   348   349   350   351   352   353   354   355   356   357   358