Page 167 - DCAP408_WEB_PROGRAMMING
P. 167

Unit 5: Scripting Language




          If the line: alert(“Hello upendra!!”) in the example above had not been put within a function, it  Notes
          would have been executed as soon as the line was loaded. Now, the script is not executed before
          a user hits the input button. The function displaymessage() will be executed if the input button
          is clicked.

          The return Statement

          The return statement is used to specify the value that is returned from the function. So, functions
          that are going to return a value must use the return statement.


                 Example:
                         <html>
                         <head>
                         <script  type=”text/javascript”>
                         function  product(x,y)
                         {
                         return  x*y;
                         }
                         </script>
                         </head>
                         <body>
                         <script  type=”text/javascript”>
                         document.write(product(9,6));
                         </script>
          5.8 Dialog Boxes


          Three Types of Dialog Boxes in JavaScript
              alert()
              confirm()

              prompt()
          alert()

          The simplest to direct output to a dialog box is to use the alert() method.

          alert(“Click  Ok  to  continue.”);




             Notes  Note that the alert() method doesn’t have an object name in front of  it. This is
             because the alert() method is part of the window Object. As the top-level object in the
             Navigator Object Hierarchy, the window Object is assumed when it isn’t specified.
          The script alert(“Click Ok to continue.”); and HTML holding the script will not continue  or
          execute until the user clicks the OK button.





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