JavaScript - Alert boxes

Computer Education, Training & Tutorial Resources - ComputerEducationWorld.com
Home » Free Web Designing Courses » Introduction to JavaScript »

An alert box is a small window that pops up with a yellow warning sign and a (usually) important message. With JavaScript we can either show a message to the user either before a page loads or in response to a user action. Here we will make an alert box that appears before the page loads. It will look like this:

Exercise
1. In Notepad/EditPlus, open base.html, your starter HTML page template.
2. Now, within the <head> tags, insert the following code:
<script language= “JavaScript”>
<!–
alert(”This is a class on JavaScript”);
//–>
</script>

This makes a pop-up box which says “This is a class on JavaScript” with an OK button that allows the user to close it and continue. The message can be changed to whatever you like. This type of pop-up box is called an alert box because it can only be used to alert a viewer. It cannot be used to control where the user may go. alert() is a method that takes care of displaying the box. The line “This is a class on JavaScript” is the parameter for the alert() method. Some more examples of methods are:
confirm(”put message here”) ; This is the next type of box we’ll be looking at. prompt(”put request here”) ; This asks the user to enter some text.

You probably noticed at the end of a method, after the right parenthesis, there is a semi-colon. In JavaScript, a semi-colon is used to end a “statement”.


• • •
 



captcha PHP Script Free PHP captcha script free php
Website Design by WebWalas.com