Javascript Pop-up Boxes - Pop-up Boxes
(Page 2 of 4 )
There are three types of Pop-up boxes in Javascript. They are the Alert Box, the Confirm Box, and the Prompt Box. Let's take a look at each one.
Alert! Will Robinson
Speaking of complexes, that kid must have had some issues. I mean every five seconds, he is sitting on some planet, chilling, and this big robot flies out of nowhere yelling Danger Will Robinson! That kid must have had a lot of changes of underwear on hand if you dig what I'm saying.
An Alert Box is used to relay information to the user. You can program them several ways. In this example we will make a simple Alert Box that displays when the page loads.
<html>
<head>
<script type="text/javascript">
alert("Look an alert box!")
</script>
</head>
<body>
</body>
</html>
If you load this page it will show a pop-up box that says Look an alert box! followed by an OK button. The user must click the OK button to continue.
If we want to add another pop-up box, we can do that also:
<html>
<head>
<script type="text/javascript">
alert("Look an alert box!")
alert("Where?!?")
</script>
</head>
<body>
</body>
</html>
This will result in the following two images:


You could also make the button say both things, using a line break:
<html>
<head>
<script type="text/javascript">
alert("Look an alert box!" + 'n' + "Where?!?")
</script>
</head>
<body>
</body>
</html>
This would result in:

Next: Confirm Box >>
More JavaScript Articles
More By James Payne