There are three types of pop-up boxes – alert, confirm, and prompt. The simplest, and most commonly used pop-up is alert. Alert takes one argument – a message to the user. When a alert box pops up, the user cannot continue until they press the "OK" button. The code for an alert box is simple:
alert("This is an alert")
The confirm box is only slightly more complicated. Like alert, confirm takes one argument – the message. When a confirm box pops up, the user is given a choice of answering using the "OK" or "Cancel" buttons. Unlike alert, confirm has a return value – 0 means the user pressed "Cancel" and 1 means "OK". The code for a confirm box is identical to an alert box except that you want to collect the return value somehow:
save_me=confirm("This is a confirm pop-up")
Although it is the most complicated of the pop-ups, prompt is still quite simple. Prompt takes two arguments – a message to the user and a default value (or "" if you want no default value.) When the prompt box pops up, the user can enter the requested information and press "OK". There is also a "Cancel" button. The return value is the user's response. If the user cancels the return value is null. If they leave the prompt box empty, the return value will be the empty string (""). You probably want to check for these values and do something special rather than use null or the empty string as their response. The code for an prompt box is:
response=prompt("This is a prompt", "Respond here")
You can view a demonstration of these pop-up boxes here
This site needs an editor - click to learn more!
You Should Also Read:
Editor's Picks Articles
Top Ten Articles
Content copyright © 2019 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.