Page 310 - Web Applications (803) Class 11
P. 310

The alert( ) Method

              Ð ÐThis dialog box is used to show the user a warning message. When a user enters inaccurate information, the
                 developer will utilise an alert box to show the user a warning or error.

              Ð ÐIt has a little triangular icon, a user-customized message, and an OK button.

              Ð ÐWhen this dialog box displays, all execution is halted and the user is asked to press the OK button.
              Ð ÐIt can also be used for debugging to see if the program is running in the correct order by providing output.
               ÐThe appearance of the alert() box varies from browser to browser.
              Ð
              Ð ÐIt can display a valid expression, string, or variable value that is supplied to the alert( ) method as an argument.
              Example:
                 <HTML>
                 <HEAD><TITLE>Dialog Box </TITLE></HEAD>
                 <BODY>
                 <H1> Learning JavaScript Alert </H1>
                 <script type="text/javascript">
                 alert(10+5*3)
                 </SCRIPT>
                 </BODY> </HTML>
              Output:

















              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.

                308     Touchpad Web Applications-XI
   305   306   307   308   309   310   311   312   313   314   315