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>
function show_alert()
{
alert("I am an alert box!");
}
</script>
</head>
<body>
</body>
</html>
<head>
function show_alert()
{
alert("I am an alert box!");
}
</script>
</head>
<body>
</body>
</html>
Try it yourself »
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>
function show_confirm()
{
var r=confirm("Press a button");
if (r==true)
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
}
}
</script>
</head>
<body>
</body>
</html>
<head>
function show_confirm()
{
var r=confirm("Press a button");
if (r==true)
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
}
}
</script>
</head>
<body>
</body>
</html>
Try it yourself »
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>
function show_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>
</body>
</html>
<head>
function show_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>
</body>
</html>
Try it yourself »
More Examples
Harvest Painless Time Tracking
Keep track of development time easily with Harvest. Start a timer from your web browser, desktop or mobile device in seconds.Get started with a free 30-day trial today.
No comments:
Post a Comment
comment.........