Using JavaScript you can create three kinds of pop-up boxes, Alert box, Confirm box and prompt box.
Alert Box
An alert box is 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 on "OK" to processed.
Syntax:
alert("Alert Text")
Example:
<html>
<head>
<script type="text/javascript">
function display_alert()
{
alert("This is an alert box!")
}
</script>
</head>
<body>
<input type="button" onclick="display_alert()" value="Display alert box"/>
</body>
</html>
Preview:
Conform box
A conform box is used if you want the user to verify or accept something. When a conform box pops up, the user will have to click either "OK" or "Cancel" to processed. If the user clicks "OK" the box returns true. If the user clicks "Cancel", the box returns false.
Syntax:
confirm{"Conform Text")
Example:
<html>
<head>
<script type="text/javascript">
function display_conform(){r=confirm("Press a button");
if (r===true)
{
alert("You pressed OK!");
}
else
alert("You pressed Cancel");
}
</script>
<body>
<input type="button" onclick="display_conform()" value="Display a confirm box"/>
</body>
</html>
Preview:
Prompt Box
A prompt box is 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 "OK" or "Cancel" to processed entering in input value.
If the use 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">
function display_prompt(){name=prompt("Please enter your name", "Your Name");
if ((name!=null) && name!=" ")
{
alert("Hello "+name+"! How are you today?");
}
}
</script>
</head>
<input type="button"onclick="display_prompt()" value="Display a prompt box"/>
</body>
</html>
Preview:
Related Search Terms
Related Posts:
How To Create Simple Image Slideshow Using JavaScript ?
Image Slideshow with Navigation Buttons Using JavaScript
How to create Changeable Date and Time Using JavaScript?
How to Create JavaScript Image Slideshow with LInks
How to Display Date Format in JavaScript?
How to Validate a HTML Form Using JavaScript?
What are the Different Ways to Redirect Page in JavaScript?
How to Detect Visitor's Browser Using JavaScript?
How to make rounded corners border using CSS
How to Create Custom CSS Template for Printing
How to create a simple form using HTML?
0 Response to "How to Show Pop Up Boxes Using JavaScript?"
Post a Comment