How to use javascript pop-up menus

Javascript has three types of popup boxes

  • Alert
  • Confirm
  • Prompt

ALERT

Javascript alert are the kind of  information to the user.

If you have not enabled the JavaScript on your web browser, then you may not able to get “alert” messages.  The JavaScript alert is a dialogue box that pops up and takes the focus away from the current window and forces the web browser to read the message.

SYNTAX:

alert(“your message”);

EXAMPLE:

<html>
<head>
<script type="text/javascript">
function display()
{
alert("Hai! Welcome to Learnwebdevelopment.info");
}
</script>
</head>
<body>
<input type="button" onclick="display()" value="click" />
</body>
</html>

CONFIRM

Confirm are the kind of confirmation given by the user.  Javascript confirm box is different from the alert box, because the confirmation box requires user action. For eg: Clicking Ok/Cancel button., etc

SYNTAX:

confirm(“your message”);

EXAMPLE:


<html>

<head>

<script type="text/javascript">

function display()

{

var r=confirm("Press a button");

if (r==true)

{

alert("Hai! Welcome to Learnwebdevelopment.info");

}

else

{

alert("Thank you visit again");

}

}

</script>

</head>

<body>

<input type="button" onclick="display()" value="click" />

</body>

</html>

PROMPT

Prompt allows the user to enter the information for further processing of the website.

SYNTAX:

prompt(“your message”);

EXAMPLE:


<html>

<head>

<script type="text/javascript">

function display()

{

var name=prompt("Please enter your name","");

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

{

document.write("<p>Hai! " + name + " Welcome to Learnwebdevelopment.info</p>");

}

}

</script>

</head>

<body>

<input type="button" onclick="display()" value="click" />

</body>

</html>
Posted in Javascript Tagged with: ,