Page 113 - DCAP202_Fundamentals of Web Programming
P. 113

Fundamentals of Web Programming




                    Notes          How to initialize a Local variable?
                                   Any variable that is initialized inside a function using the var keyword will have a local scope.
                                   If a variable is initialized inside a function without  var, it will have a global  scope. A  local
                                   variable can have the same name as a global variable.
                                   var  a  =  10;
                                   disp_a();
                                   function  disp_a()
                                    {
                                     var  a  =  20;
                                     alert(“Value  of  ‘a’  inside  the  function  “  +  a);
                                    }
                                   alert(“Value  of  ‘a’  outside  the  function  “  +  a);

                                   Self Assessment

                                   Fill in the blanks:
                                   9.  To keep the browser from executing a script when the page loads, you can put your script
                                       into a ...........................
                                   10.  A ........................... is an expression that defines an unnamed function.
                                   11.  An ........................... function saves us from rewriting the same code again and again and
                                       helps us to make our application smaller.
                                   12.  The ........................... object is a local variable available within all functions.

                                   13.  ..........................variables exist only inside a particular function hence they have Local Scope.
                                   8.4 Dialog Boxes


                                   JavaScript supports three important types of dialog boxes. These dialog boxes can be used to
                                   raise and alert, or to get confirmation on any input or to have a kind of input from the users.

                                   Here we will see each dialog box one by one:
                                   8.4.1 Alert Dialog Box

                                   An alert dialog box is mostly used to give a warning message to the users. Like if one input field
                                   requires to enter some text but user does not enter that field then as a part of validation you can
                                   use alert box to give warning message as follows:
                                   <head>
                                   <script  type=”text/javascript”>
                                   <!—
                                     alert(“Warning  Message”);
                                   //—>
                                   </script>
                                   </head>
                                   Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only  one
                                   button “OK” to select and proceed.

                                   8.4.2 Confirmation Dialog Box

                                   A confirmation dialog box is mostly used to take user’s consent on any option. It displays a
                                   dialog box with two buttons: OK and Cancel.


          106                               LOVELY PROFESSIONAL UNIVERSITY
   108   109   110   111   112   113   114   115   116   117   118