Alert boxes are used to provide additional information and are commonly used to warn the visitor that a form hasn't been filled in properly.
Alert boxes contain an Icon with an ! similar to the one above. The title bar of the alert varies according the the browser used and cannot be changed.
Alert boxes only have 1 button with OK on it. Again this cannot be changed.
Clicking the OK button returns nothing to the browser, effectively clicking the OK button closes the dialog.
The only part of an alert box you have control over is the text. Syntax for an alert is simple.
alert("whatever message you want"); - (script tags omitted)
Here is a full syntax example - Click here to test alert
and the code
<a href="alert.shtml" onClick="alert('this page will now reload');">Click here to test alert</a>If you want more than 1 line of text then all you have to do is use \n where you want the new line to start. For example
alert("whatever \nmessage \nyou \nwant");
Generated strings can also be sent to the alert box and displayed like this. 3 line alert
The code
<script language="JavaScript" type="text/javascript">Notice that alert(alert_msg); there are no " " surrounding alert_msg and that alert_msg matches the string name in the javascript. There's nothing to stop you creating multiple strings and calling them from the alert.
For example
View my first messageThe code
<script language="JavaScript" type="text/javascript">So that's about all there is to the alert box.
Next we'll look at the prompt box.