Page 204 - Web_Application_v2.0_C12_Fb
P. 204
txt_str = "You pressed Cancel! Goodbye!";
}
document.getElementById("code").innerHTML = txt_str;
}
</SCRIPT>
</HEAD>
<BODY>
<h2>Using Confirm Box in JavaScript</h2>
<p id="code">
<input type="button" onclick="display()" value="Click Here">
</p>
</BODY>
</HTML>
Output:
When Click Here button is clicked, it displays: When OK button is clicked, it displays:
Example 14: To demonstrate the use of prompt function
In this example the function func1( ) is called and executed when the button is clicked. The prompt function
asks the user to enter a value. In case the value entered is not null (or blank left by user) the respective value
is displayed in the body of the webpage.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Prompt Box</TITLE>
</HEAD>
<SCRIPT>
function func1() {
var age = prompt("Enter your Age","45");
if (age != null){
202 Touchpad Web Applications (Ver. 2.0)-XII

