Page 168 - DCAP408_WEB_PROGRAMMING
P. 168

Web Programming




                    Notes          Generally, the alert() method is used for exactly that – to warn the user or alert him or her to
                                   something. Examples of this type of use include:

                                      Incorrect information in a form
                                      An invalid result from a calculation
                                      A warning that a service is not available on a given date
                                   Nonetheless, the alert() method can still be used for friendlier messages.




                                     Notes  Note that Netscape alert boxes include the phrase “<url> [JavaScript Application]”
                                     in the title bar of the alert while IE has “Microsoft Internet Explorerin the title bar of the
                                     alert. Both have yellow triangles to “alert” you. This done in order to distinguish them
                                     form those generated  by the operating system or the browser. This done for security
                                     reasons so that malicious programs cannot trick users into doing things they don’t want to
                                     do.
                                   <INPUT  TYPE=”button”  VALUE=”alert”  onClick=”alert(‘This  is  an  alert!!’)”>
                                   OR
                                   <INPUT  TYPE=”button”  VALUE=”alert”  onClick=”window.alert(‘This  is  an
                                   alert!!’)”>
                                   The alert dialog box is used  to display an alert message to the user.

                                   prompt()

                                   The alert() method still doesn’t enable you to  interact with the user. The addition of the OK
                                   button provides you with some control over the timing of events, but it still cannot be used to
                                   generate any dynamic output or customize output based on user input.
                                   The simplest way to interact with the user is with the prompt() method. The user needs to fill in
                                   the field and then click OK.
                                   prompt(“Enter Your Name:”, “Name”);




                                     Notes

                                         You are providing two “arguments” to the method in the parenthesis. The prompt()
                                          method “requires two pieces of information”. The first is text to be displayed, and
                                          the second is the default data in the entry field.
                                         In JavaScript, when a method requires more than one argument, they are separated
                                          by commas.

                                   <INPUT  TYPE=”button”  VALUE=”prompt”  onClick=”respPrompt()”>
                                   The prompt() method dialog box allows the user the opportunity to enter information.  It takes
                                   two parameters; a message and a default string for the text entry field.
                                   With function code:

                                   <SCRIPT  LANGUAGE=”JavaScript”>
                                   function  respPrompt()  {




          162                               LOVELY PROFESSIONAL UNIVERSITY
   163   164   165   166   167   168   169   170   171   172   173