Javascript popup

In JavaScript you can create three kinds of popup boxes: Alert box, Confirm box, and Prompt box.

Alert Box

An alert box is often used if you want to know input from user.
When an alert box pops up, the user will have to click “OK” to proceed.

Syntax:

alert(“learnwebdevelopment”);

Example:

function showalert()
{
alert(‘Welcome to Learn Webdevelopment site!!!’);
}
<input type=”button” onclick=”showalert();” value=”Show Alert”>

Display:

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(“Are you sure want to delete this employee?”);

Example:

function showconfirm()
{
var answer = confirm(“Are you sure want to leave from this site?”);
if (answer)
{
alert(“Bye bye!”);
window.location = “http://qualitypointtech.net”;
}
else{
alert(“Thanks for staying here!”)
}

}

<input type=”button” onclick=”showconfirm();” value=”Leave from this site”>

Display:

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(“learnwebdevelopment”,”defaultvalue”);

Example:

function showprompt()
{
var reply = prompt(“Hello! What’s your name?”, “”);
alert ( “Nice to see you here ” + reply + “!”);
}

<input type=”button” onclick=”showprompt();” value=”Say my name!”>

Display:

Posted in Javascript Tagged with: