Page 115 - CodePilot V5.0 C8
P. 115

<TITLE>Using Function</TITLE>  The following HTML code demonstrates the use of Alert Box in JavaScript:

 <SCRIPT>
                    Code
 function changeColour()     Create a web page to demonstrate the use of Alert Box in JavaScript.
                      6
 {

 document.body.style.backgroundColor = "lightblue";  <!DOCTYPE HTML>
 }               <HTML>
 </SCRIPT>       <HEAD>

 </HEAD>         <TITLE>Form Submission Alert</TITLE>
                 <SCRIPT>
 <BODY>
                 {
 <H1>Click the Button to Change the Background Colour</H1>
                 alert("Please fill out all fields.");
 <BUTTON onclick="changeColour()"> Change Colour </BUTTON>
                 }
 </SCRIPT>
                 </SCRIPT>
 </BODY>
                 </HEAD>
 </HTML>
                 <BODY>
 The output of the preceding HTML code is as follows:
                 <H1>Contact Form</H1>
                 <FORM>
                 <LABEL>Name:</LABEL>
                 <INPUT TYPE="TEXT" ID="NAME" NAME="NAME" REQUIRED><BR><BR>

                 <LABEL>Email:</LABEL>
                 <INPUT TYPE="EMAIL" ID="EMAIL" NAME="EMAIL" REQUIRED><BR><BR>
                 <BUTTON TYPE="SUBMIT">Submit</BUTTON>

                 </FORM>
 The function changes the background colour of the web page to light blue using JavaScript.  </BODY>

 PRIVACY PRACTICES  </HTML>
                 The output of the preceding HTML code is as follows:
 Developers should always sanitize data. This means they need to ensure that the data a user
 enters into a website is safe before using it.






 JAVASCRIPT POPUP BOXES

 The JavaScript popup boxes are used to interact with users by displaying messages or requesting
 input. There are three main types of popup boxes: Alert Box, Confirm Box and Prompt Box.


 ALERT BOX       CONFIRM BOX

 The Alert box displays a message and can only be closed by the user clicking the OK button.     A Confirm Box asks the user to confirm or cancel an action. If the user clicks OK, it returns true;
 This box is often used to show important information or warnings. The alert() function is used to   if Cancel is clicked, it returns false. The confirm() function is used to trigger the confirm box.
 trigger the alert box.  It’s commonly used for actions like deleting or submitting forms.



                                                                                                                  113
                                                                                            JavaScript for Beginners
   110   111   112   113   114   115   116   117   118   119   120