HTML and CSS Reference
In-Depth Information
The message for the alert dialog box is any valid expression, variable, or a string of
text enclosed in matching quotes, and sent as a single argument to the alert() method.
HTML tags are not rendered within the message string but you can use the escape
sequences, \n and \t . A word of caution: Don't overuse the alert box on your Web site. It
can be seriously annoying for visitors. Use the alert box for its intended purpose: to alert
visitors about input or processing problems and briefly explain how to correct them.
FORMAT
alert("String of plain text");
alert(expression);
EXAMPLE
alert("Phone number is incorrect");
alert(a + b);
EXAMPLE 4.1
<html>
<head><title>Dialog Box</title></head>
<body bgcolor="yellow" text="blue">
<b>Testing the alert method</b><br />
<h2>
1
<script type="text/javascript">
2
document.write("It's a bird, ");
document.write("It's a plane,<br />");
3
alert("It's Superman!") ;
</script>
</h2>
</body>
</html>
EXPLANATION
1
The <script> tag starts the JavaScript program. The JavaScript engine starts exe-
cuting code from here until the closing </script> tag. JavaScript does not under-
stand HTML tags unless they are embedded in a string.
2
The document.write() method sends its output to the browser.
3
The alert() method will produce a little dialog box, independent of the current
document, and all processing will be stopped until the user clicks the OK button.
This little box can be moved around the screen with your mouse.
Search WWH ::




Custom Search