Page 212 - Web Applications (803) Class 12
P. 212
confirm(“message”) If you want the user to verify or accept information, a
confirm box is frequently utilised.
The user will have to either “OK” or “Cancel” in a confirm
window to continue.
The box returns true if the user selects “OK”, otherwise false
if the user clicks “Cancel.”
prompt(“message”) If you want the user to enter a value before seeing a page,
a prompt box is frequently utilised.
The user must click “OK” or “Cancel” to continue after
providing an input value when a prompt box appears.
The input value is returned to the box if the user hits “OK.”,
otherwise returns null if the user clicks the “Cancel” button.
Let’s see some examples which use these functions.
Example 1—Alertbox
In this example the functions myFunction1( ) and myFunction2( ) are called and executed when the respective
button is clicked. The first function display text in an alert box. The second function adds 3 numbers and then
displays the result.
<html>
<head>
<script>
function myFunction1()
{
alert("Hi!\nIts a Beautiful day!");
}
function myFunction2()
{
var sum=3+5+8;
alert("The sum is "+sum);
}
</script>
</head>
<body>
<h2>JavaScript code to display text in 2 lines in an alertbox</h2>
<input type="button" onclick="myFunction1()"value="Click Me">
<h2>JavaScript code to add 3 numbers</h2>
<input type="button" onclick="myFunction2()"value="Click to add 3,5,8">
</body> </html>
210 Touchpad Web Applications-XII

