• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Dialog Boxes in JavaScript

JavaScript Dialog Boxes

JavaScript has three kind of popup boxes : Alert box, confirm box, and Prompt box.

 

Alert Box

An alert box is often used if you want to make sure information comes through to the user.

When an alert box pops up, the user will have to click “ok” to proceed.

Syntax

alert(“sometext”);

 

Example

<html>

<head>

<script type=”text/javascript”>

functionshow_alert()

{

alert(“I am an alert box :”) ;

}

</script>

</head>

<body>

<input type=”button”  onclick=”show_alert()”   value=”show alert box” />

</body>

</html>

 

Confirm Box

A confirm box is often used if you want the user to verify or accept something.

When a confirm box pops up, the user will have to click either “OK” or “cancel” to proceed.

If the user clicks “OK”, the box returns true. If the user clicks “Cancel” , the box returns false.

Syntax

confirm(“sometext”);

 

Example

<html>

<head>

<script type=”text/javascript”>

functionshow_confirm()

{

var r=confirm(“Press a button”);

if (r==true)

{

alert(“you pressed OK!”);

}

else

{

alert(“you pressed cancel!”);

}

}

</script>

</head>

<body>

<input type=”button” onclick=”show_confirm()” value=”show confirm box” />

</body>

</html>

 

Prompt Box

A prompt box is often used if you want the user to input a value before entering a page.

When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value. If the user clicks “OK” the box returns the input value. If the user clicks “Cancel” the box returns null.

Syntax

prompt(“sometext”,”defaultvalue”);

 

Example

<html>

<head>

<script type=”text/javascript”>

functionshow_prompt()

{

var name=prompt(“Please enter your name”,”Harry potter”);

if (name!=null  && name!=””)

{

document.write(“Hello ” + name + “ ! How are you today?”);

}

}

</script>

</head>

<body>

<input type=”button” onclick=”show_confirm()” value=”show prompt box” />

</body>

</html>

Summary
Review Date
Reviewed Item
Dialog Boxes in JavaScript
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Dialog Boxes in JavaScript"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.