Javascript2

Popup Boxes


«<Javascript1|Javascript3»>

Alert Box

Alert box is a dialog box which displays a message in a small window with an OK button, user have to click on the ok button to proceed.

Example

<html>
<head>
</head>
<body>
<script type="text/JavaScript">

alert("Hit me to proceed")
document.write(" Have a nice day ");

</script >
</body>
</html>

Understanding the program:
User can type his desired message with the alert box in the quotes like alert(“what ever text user want “). This message will be displayed with the alert window to guide the user.

Output is:

Have a nice day

Click alert to view result of this program on browser
[Top]

Prompt Box

Prompt box is a dialog box which displays a message in a small window with a text box along with two buttons . One OK and other Cancel. Prompt method has ability to return the text kept with the prompt method's text box , this value can be assigned to some variable and can be used as and when require.

Example

<html>
<head>
</head>
<body>
<script type="text/JavaScript">

prompt ("Enter your name", "")

</script >
</body>
</html>

Understanding the program:
A dialog box with a text box and two buttons will appear, the message typed with prompt method will be displayed on the dialog box the text box will appear blank , if any text is typed at the place of blank (“ ”), that text will appear in the text box on dialog box.
Click prompt1 to view result of this program on browser

Example

<html>
<head>
</head>
<body>
<script type="text/javascript">

prompt ("Enter your name", " enter your name here")

</script >
</body>
</html>

Understanding the program :
A dialog box with a text box and two buttons will appear, the message typed with prompt method will be displayed on the dialog box the text box will appear filled with “ enter your name here “ text.

Storing value accepted from a prompt box in variables :

<html>
<head>
</head>
<body>
<script type="text/javascript">

var name,address name=prompt ("Enter your name", " enter your name here")
address = prompt ("Enter your address", "Address Please ")
document.write("Your Name : "+name);
document.write("<br>Your Address : "+address);

</script >
</body>
</html>

Understanding program :
As we know that prompt method has the ability to return the text stored in it’s text box, so the name fed by the user will be stored in the name variable and address of user in address variable, which will be displayed on the screen by document.write method.
If u entername Harshith and address India the o/p is as fallows..
Output is :

Your Name : Harshith
Your Address : India

Click prompt2 to view result of this program on browser
[Top]

Confirm Box

Confirm box is a dialog box which displays a message in a small window with two buttons. One Ok and other Cancel. This method can be used to get the response of user in positive by clicking on ok and in negative by clicking on cancel. The value returned by the confirm method in case of OK is true and in case of Cancel is false. A programmer can program the code for positive and negative situations depending on the response returned by the user.

Example

<html>
<head>
</head>
<body>
<script type="text/JavaScript">

a=confirm(" Want to Proceed ? ");
document.write("Your have clicked on : "+a);

</script >
</body>
</html>

Understanding the program:
If user will clicks on Ok then you have clicked on true will appear
If user will clicks on Cancel then you have clicked on false will appear
Click confirm to view result of this program on browser
[Top]
«<Javascript1|Javascript3»>

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.