March 16, 2011

0 Javascript Alert boxes

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:



JavaScript alert box


Steps to Follow

1. In Notepad, open base.html, your starter HTML page template.

2. Now, within the tags, insert the following code:




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

0 comments:

Post a Comment

Blogger Themes

 
Powered by Blogger