JavaScript Basics :
POP UP BOXES








It is possible to make three different kinds of popup windows.

Try clicking the buttons below to see the differences:








ALERT BOX

The syntax for an alert box is: alert("yourtext");

The user will need to click "OK" to proceed.

Typical use is when you want to make sure information comes through to the user.

Examples could be warnings of any kind.
(Typical examples are "Adult Content", or technical matters like "This site requires Shockwave Flash plug-in").




CONFIRM BOX:

The syntax for a confirm box is: confirm("yourtext");

The user needs to click either "OK" or "Cancel" to proceed.

Typical use is when you want the user to verify or accept something.

Examples could be age verification like "Confirm that you are at least 57 years old" or technical matters like "Do you have a plug-in for Shockwave Flash?"

- If the user clicks "OK", the box returns the value true.
- If the user clicks "Cancel", the box returns the value false.

if (confirm("Do you agree")) {alert("You agree")}
else{alert ("
You do not agree")};


Note: The if statement is explained later in this tutorial.




PROMPT BOX:

The prompt box syntax is: prompt("yourtext","defaultvalue");

The user must click either "OK" or "Cancel" to proceed after entering the text.

Typical use is when the user should input a value before entering the page.

Examples could be entering user's name to be stored in a cookie or entering a password or code of some kind.

- If the user clicks "OK" the prompt box returns the entry.
- If the user clicks "Cancel" the prompt box returns null.

Since you usually want to use the input from the prompt box for some purpose it is normal to store the input in a variable, as shown in this example:

username=prompt("Please enter your name","Enter your name here");


 << PREVIOUS
READ MORE >>  
















DEVELOPER TIP!





     "Better Than Books - As Easy As It Gets!"