Page 169 - DCAP408_WEB_PROGRAMMING
P. 169

Unit 5: Scripting Language




                  var  favorite  =  prompt(‘What  is  your  favorite  color?’,  ‘RED’);         Notes
                  //  OR  var  favorite  =  window.prompt(‘What  is  your  favorite  color?’,  ‘RED’);
               // if (favorite) equivalent to if (favorite != null && favorite != “”);
                  if  (favorite)  alert(“Your  favorite  color  is:  “  +    favorite);
                  else  alert(“You  pressed  Cancel  or  no  value  was  entered!”);
          }
          </SCRIPT>




             Notes  What happens when you press Cancel? The value null is returned.
           confirm()


          Confirm displays a dialog box with two buttons: OK and Cancel. If the user clicks on OK the
          window method confirm() will return true. If the user clicks on the Cancel button  confirm()
          returns false.

          <INPUT  TYPE=”button”  VALUE=”confirm”  onClick=”respConfirm()”>
           The confirm dialog box returns a Boolean value based on the user’s selection.
          With function code:
          <SCRIPT  LANGUAGE=”JavaScript”>
          function  respConfirm  ()  {
                    var  response  =  confirm(‘Confirm  Test:  Continue?’);
                    //  OR  var  response  =  window.confirm(‘Confirm  Test:  Continue?’);
                    if  (response)  alert(“Your  response  was  OK!”);
                    else  alert(“Your  response  was  Cancel!”);
          }
          </SCRIPT>




             Notes  Response will be:
             1.  true if OK is pressed

             2.  false if Cancel is pressed
          5.9 String Manipulation Functions


          The most important string manipulation functions are the following:
              length
              toLowerCase

              toUpperCase
              charAt
              indexOf



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