Page 311 - Web Applications (803) Class 11
P. 311
Ð ÐAfter hitting the OK button, the prompt( ) method returns the value. It returns the input value if it is entered;
otherwise, if the user clicks the Cancel button, it returns null.
Example:
<HTML>
<HEAD>
<TITLE>Using prompt box</TITLE>
</HEAD>
<BODY>
<script type = "text/javascript">
var age=prompt("Enter Age”, "18");
if (age == null || age == " ") // If user clicks the Cancel button
{
alert("No input received");
}
else if(age < 18)
{
alert("You can get a learner's licence only");
}
else
{
alert("You can get a driver's licence");
}
</SCRIPT>
</BODY>
</HTML>
Output:
When you click on the “OK” button, with the message “this page says”. Then a new window opens with the message
“You can get a driver’s licence”.
Introduction to Dynamic Websites Using JavaScript 309

