Page 203 - Web_Application_v2.0_C12_Fb
P. 203
<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>
Output:
When Click Me button is clicked, it displays: When Click to add 3,5,8 button is clicked, it displays:
Example 13: To demonstrate the use of confirm function
In this example the function display( ) is called and executed when the button is clicked. This calls the confirm
function which prompts the user to press a button. Depending on the button pressed, the respective text is
displayed in the body of the webpage. The getElementById() method returns the element whose id matches.
A specific value is returned otherwise in case the element does not exist, then null is returned. In this example
<p> tag is returned which allows text to be written in the body of the webpage.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Confirm Box</TITLE>
</HEAD>
<SCRIPT>
function display() {
var txt_str;
if (confirm("Press a button!")) {
txt_str = "You pressed OK! Have a great day";
} else {
JavaScript Part 2 201

