1. Write a HTML program to demonstrate Formatting Tags. Aim: To write a HTML program to illustrate Formatting Tags.
<html>
<head>
<title>Example - Text Formating Tags</title> </head>
<body>
<h1>Header Size 1</h1> <p><h3>Header Size 3</h3>
The Next Line of example text should be in the middle of the document
<center>
<p><b>Bold Text</b>, <i>Italic Text</i>, <u>and underlined text.</u>
</center>
<p><font size="5">Font size = 5</font>
<br><font face="arial">Font Face = Arial</font>
<br><font color="#FF0000">Font Colour = Red</font> <p>Normal Text, <sub>Subscript text</sub>, <sup>Supersrpit Text</sup>
<p><em>Text in Emphasis</em> <br><strong>Text in Strong</strong> <pre>
This is preformatted text (using the PRE) tag as it appears in the editor
view the source code and you will
notice that there are no tags until here. It is dsiplayed the exact way that its been
set out in the editor. If required the font can be changed <font face="arial">like this</font> using
</pre>
<tt>This text should appear as if it has been typed by a typewriter</tt>
<p>
<small>The fine print (small text)</small> <hr>
<center>
<font size="2">--- End Of Example ---</font> </center>
</body> </html>
Output:
2. Write a HTML program to demonstrate Inter Documented Links. Aim: To write a HTML program to demonstrate Inter Documented Links.
<html>
<title>Inter Documented Links</title> </head>
<body> <p>
<a href="#c10">See also Chapter 10.</a> </p>
<h2><a name="C1">Chapter 1 </h2>
<p>this chapter explains ba bla bla</p> <h2>Chapter 2 </h2>
<p>This chapter explains ba bla bla</p> <h2>Chapter 3 </h2>
<p>This chapter explains ba bla bla</p> <h2>Chapter 4 </a></h2>
<p>This chapter explains ba bla bla</p> <h2>Chapter 5 </h2>
<p> This chapter explains ba bla bla</p> <h2>Chapter 6 </h2>
<p> This chapter explains ba bla bla</p> <h2>Chapter 7 </h2>
<p> This chapter explains ba bla bla</p> <h2>Chapter 8 </h2>
<p> This chapter explains ba bla bla</p> <h2>Chapter 9 </h2>
<p> This chapter explains ba bla bla</p> <h2><a name="C10">Chapter 10 </h2>
<a href="#c1">See also Chapter 1.</a> </p>
</body> </html>
Output:
3. Write a HTML program using <hr> and headings tags. Aim: To write a Write a html program using <hr> and headings tags. <html>
<head>
<title> This is Sample Page</title> </head>
<body>
<hr width="50%" size="15" color="blue">
<h2 align="center">This is heading…2</h2> <h3 align="center">This is heading…3</h3> <h4 align="center">This is heading…4</h4> <h5 align="center">This is heading…5</h5> <h6 align="center">This is heading…6</h6>
<p align="center">This is Basic Web Page Example. <br>I am studying B. Sc
III year(M.S.CS)<br>This is the first time I am learning HTML</p> <hr width="50%" size="15" color="red">
</body> </html>
Output:
4. Write a HTML program to illustrate all types of Lists in HTML. Aim: To write a HTML program to illustrate all types of Lists in HTML.
<html>
<head>
<title>Lists in HTML</title> </head>
<body>
<h2><u>Using Ordered and Unordered Lists</u></h2> <h3>Courses offerd by B V Raju College</h3>
<ol type="1" start="1"> <li>BSc</li>
<li>MPCs</li> <li>MSCs</li> <li>MPC</li> <li>MBBTBC</li> <li>BTBCC</li> </ul>
<li>BCom</li>
<ul type="circle">
<li>Vocational</li> </ul>
<li>MSc</li>
<ul type="disk">
<li>Organic Chemistry</li> </ul>
<li>MCA</li> </ol>
<h2><u>Using Definition List</u></h2> <h3>Course Abbrevations</h3>
<dl>
<dt>BSc
<dd>Bachelor of Science</dd> </dt>
<dt>BCom
<dd>Bachelor of Commerce</dd> </dt>
<dt>MSc
<dd>Master in Science</dd> </dt>
<dt>MCA
<dd>Master in Computer Applications</dd> </dt>
</dl> </body> </html>
5. Write a HTML program to design your class time table using tables. Aim: To write a HTML program to design the class time table using tables.
<html>
<head>
<title>Time Table</title> </head>
<body bgcolor="#e6ffff">
<table border="1" cellspacing="0" cellpadding="0" align="center" width="50%" height="50%">
<br><br><br> <caption>
<b>III MECS-B Time Table</b> <br><br><br>
</caption> <colgroup>
<col span="1" style="background-color:#d6d6c2"> </colgroup>
<tr bgcolor="#d6d6c2" align="center"> <th></th>
<th>4</th>
<th rowspan="7" width="10%">Lunch break</th> <th>5</th>
<th>6</th> <th>7</th> </tr>
<tr align="center"> <th>Mon</th> <td>E4</td> <td>LS</td> <td>M4</td> <td>CS4</td>
<td colspan="3"><--CS4/E4 Lab--></td> </tr>
<tr align="center"> <th>Tue</th> <td>M4</td> <td>E4</td> <td>CS4</td> <td>CSS</td> <td>AS</td> <td>EPS</td> <td>M4</td> </tr>
<tr align="center"> <th>Wed</th> <td>E4</td> <td>EPS</td> <td>M4</td> <td>CS</td> <td>LS</td> <td>CSS</td> <td>AS</td> </tr>
<tr align="center"> <th>Thu</th> <td>CS4</td>
<td colspan="3"><--CS4/E4 Lab--></td> <td>CS4</td>
<td>CSS</td> <td>E4</td> </tr>
<th>Fri</th> <td>AS</td> <td>M4</td> <td>EPS</td> <td>LS</td> <td>CSS</td> <td>E4</td> <td>CS4</td> </tr>
<tr align="center"> <th>Sat</th> <td>M4</td> <td>CSS</td> <td>CS4</td> <td>E4</td> <td>E4</td> <td>M4</td> <td>E LAB</td> </tr>
</table> </body>
6. Write a HTML program to divide the webpage using frames. Aim: To write a HTML program to divide the webpage using frames.
Frames.html <html>
<frameset cols="15%,85%">
<frame src="frame_a.html" name="list"> <frame src="frame_b.html" name="output"> </frameset>
</html>
Frame_a.html <html>
<head>
<title>Frames</title> </head>
<body bgcolor="#ccfff5">
<h3 align="center">This Is Frame A</h3>
<a href="program2.html" target="output">Program2</href> <br><br><br>
<a href="program3.html" target="output">Program3</href> </body>
</html>
Frame_b.html <html>
<head>
<title>frame_b</title> </head>
<body bgcolor="#ffcc99">
<h1 align="center">This Is Frame B</h1> </body>
</html>
Program1.html <html>
<head>
<title>Program1</title> </head>
<body bgcolor="#99e6ff">
<h1 align="center">This is Program1</h1> </body>
</html>
Program2.html <html>
<head>
<title>Program2</title> </head>
<body bgcolor="#ff80aa">
<h1 align="center">This is Program2</h1> </body>
</html>
Program3.html
<html>
<head>
<body bgcolor="#ffffcc">
<h1 align="center">This is Program3</h1> </body>
</html> Output:
7. Write a HTML program to design a student registration form.(Assume the form fields). Aim: To write a HTML program to design a student registration form.(Assume the form fields). Registration.html
<html>
<head>
<title>Student Registration Form</title> </head>
<body bgcolor=#E0DBF0>
<form name="StudentRegistration"> <br><br><br><br><br>
<table cellpadding="2" width="25%" height="45%" bgcolor=#A8EDDE align="center" cellspacing="2">
<tr>
<td colspan=2>
<center><font size=5><b>Student Registration Form</b></font></center>
</td> </tr>
<tr>
<td><b>Name</b></td>
<td><input type=text name=textnames id="textname" size="20"></td>
<td><b>Father Name</b></td>
<td><input type=text name=textnames id="textname" size="20"></td>
</tr> <tr>
<td><b>DOB</td>
<td><input id="date" type="date"></td> </tr>
<tr>
<td><b>Gender</td>
<td><input type="radio" name="sex" value="male" size="10">Male
<input type="radio" name="sex" value="Female" size="10">Female</td>
</tr> <tr>
<td><b>Hobbies</td> <td>
<input type="checkbox" name="telugu">Telugu <input type="checkbox" name="english">English <input type="checkbox" name="hindi">Hindi </td>
</tr> <tr>
<td><b>Course</td>
<td><select name="Course">
<option value="-1" selected>select..</option> <option value="B.Tech">B.TECH</option> <option value="MCA">MCA</option> <option value="MBA">MBA</option> <option value="BCA">BCA</option> </select></td>
</tr> <tr>
<td><b>Address</td>
<td><textarea type="text" name="personaladdress"
id="personaladdress" cols="22" rows="3"></textarea></td> </tr>
<tr>
<td><b>EmailId</td>
</tr> <tr>
<td><b>MobileNo</td>
<td><input type="text" name="mobileno" id="mobileno" size="20"></td>
</tr> <tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form" /></ td>
</tr> </table> </form>
</body> </html>
Output
Aim: To write a HTML program to design the web page as above. <html>
<head>
<title>BatMobile</title> </head>
<body>
<table border=1> <tr>
<th>Special Equipment</th>
<th colspan="2">Specifications/Performace Data</th> </tr>
<tr>
<td>Retraceble protective armor</td> <td><b>Engine Type</b></td> <td>Jet Turbine</td>
</tr> <tr>
<td>Weapons System</td> <td><b>Thrust</b></td> <td>150lbs@103%ROS</td> </tr>
<tr>
<td>Instruments-Aircraft w/on-board Computer</td> <td><b>Torque</b></td>
<td>[email protected]%ROS</td> </tr>
<td rowspan="9"><img src="bus.png"></td> <td><b>Top Speed</b></td>
<td>Unknown</td> </tr>
<tr>
<td><b>Brake Rating</b></td> <td>Excellent</td>
</tr> <tr>
<td><b>Wheel Base</b></td> <td>141.0 in.</td>
</tr>
<tr>
<td><b>Length</b></td> <td>260.7 in.</td>
</tr> <tr>
<td><b>Width</b></td> <td>94.4 in.</td>
</tr> <tr>
<td><b>Height</b></td> <td>51.2 in.</td>
</tr> <tr>
<td><b>Wheels</b></td> <td>Cast alloy,15 x6.5</td> </tr>
<tr>
<td><b>Fuel Requirement</b></td> <td>high oct 97% special.</td> </tr>
</table> </body> </html>
9. Write a HTML program to demonstrate all types of style sheets.
Definition of CSS: “CSS is an acronym which means Cascading Style Sheets. CSS is a style language that defines layout of HTML documents.
For example, CSS covers fonts, colors, margins, lines, height, width, background images, advanced positions and many other things.
The basic CSS syntax The basic syntax for a CSS rule is as follows
A CSS rule is simply a statement that consists of a selector and a declaration. Selector: is the hook used to choose what part(s) of your HTML to apply the CSS to. It indicates the element to which the rule is applied. Following the selector is the…
Declaration: Inside a declaration block you can have as many declarations as you want and each declaration is a combination of a CSS Property and a value.
Property: is one of the CSS Properties used to tell what part of the selector will be changed (or styled). It specifies a characteristic, such as color, font-family, position, and is followed by a colon (:)
Value: assigns a value to the property. Types of Style Sheets
There are three types of CSS styles:
Inline Style Sheets
Internal Style Sheets
External Style Sheets
Inline styles:
Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to.
Use inline style sheets when you want to apply a style to a single occurrence of an element. Inline style sheets are declared within individual tags and affect those tags only. Inline style sheets are declared with the style attribute.
Program: <html> <head>
<title>HTML Inline CSS</title> </head>
<body>
<h3>Example on Inline Style Sheet</h3><hr> <p style = "color:red;">This is red</p>
<p style = "color:blue;">This is thick</p> <p style = "color:green;">This is green</p> </body>
Output:
Internal or Embedded Style Sheets:
Embedded styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in.
<style type=”text/css”> Style goes here </style>
Use an internal style sheet when you want an HTML document to have a unique style. An internal style sheet is defined using the <style> tag and goes in the head section of an HTML document.
Program: <html> <head>
<title>HTML Internal CSS</title> <style type = "text/css">
.red {
color: red; }
.blue{
color: blue; }
.green { color:green; }
</style> </head> <body>
<h3>Example on Internal Style Sheet</h3><hr> <p class = "red">This is red</p>
<p class = "blue">This is blue</p> <p class = "green">This is green</p> </body>
Output:
External style sheet
Use an external style sheet when you want to apply one style to many pages. If you make one change in an external style sheet, the change is universal on all the pages where the style sheet is used.
An external style sheet is declared in an external file with a .css extension. It is called by pages whose interface it will affect. External style sheets are called using the tag which should be placed in the head section of an HTML document. This tag takes three attributes.
Attributes of the tag:
rel - When using an external style sheet on a webpage, this attribute takes the value "style sheet"
type - When using an external style sheet on a webpage, this attribute takes the value "text/css"
href - Denotes the name and location of the external style sheet to be used. Program:
<html> <head>
<title>HTML External CSS</title>
<link rel = "stylesheet" type = "text/css" href = "style.css"> </head>
<body bgcolor="orange">
<h3>Example on External Style Sheet</h3><hr> <p class = "red">This is red</p>
<p class = "blue">This is blue</p> <p class = "green">This is green</p> </body>
Style.css .red {
color: red; }
.blue{
color: blue; }
.green {
color:green; }
Output:
10. Write a HTML program to demonstrate Layers in CSS.
Aim: To Write a HTML program to demonstrate Layers in CSS. <html>
<head>
<style type="text/css" rel="stylesheet" media="all"> .red
{
background-color:red; width:500px;
height:200px; position:relative; top:50px;
left:120px; z-index:1; }
.blue {
background-color:blue; width:500px;
height:200px; position:relative; top:-50px;
z-index:2; }
.green {
background-color:green; width:500px;
height:200px; position:relative; top:-100px; left:200px; z-index:3; }
</style> </head> <body>
<h2>Example on Layers in CSS</h2> <div class="red" >
</div>
<div class="blue"> </div>
<div class="green"> </div>
</body> </html> Output:
Aim: To Write a Javascript program to perform all arithmetical operations using forms.
Calculator.html <html>
<head>
<title>A Simple calculator</title>
<script language="javascript" src="math.js"> </script>
</head>
<body bgcolor="#ffb3b3">
<h2 align="center"> A Simple Calculator</h2> <form name="calc">
<table border=0 align="center" bgcolor="#e6ffe6" height="200px">
<tr>
<td>Enter first number:</td>
<td><input type="text" name="first"></td> </tr>
<tr>
<td>Enter second number:</td>
<td><input type=text name="second" ></td>
</tr> <tr>
<td>Result:</td>
<td><input type=text name="res"></td> </tr>
<tr >
<td colspan=4 align="center"> <input type=button value="ADD" onclick="findSum()">
<input type=button value="SUB" onclick="findSub()">
<input type=button value="MUL" onclick="findMul()">
<input type=button value="DIV" onclick="findDiv()">
<input type=reset value="Clear"> </td>
</form> </body>
</html> Math.js
function findSum() {
var n1=parseInt(document.calc.first.value); var n2=parseInt(document.calc.second.value); result=n1+n2;
document.calc.res.value=result; }
function findSub() {
var n1=document.calc.first.value; var n2=document.calc.second.value; result=n1-n2;
document.calc.res.value=result; }
function findMul() {
var n1=document.calc.first.value; var n2=document.calc.second.value; result=n1*n2;
document.calc.res.value=result; }
function findDiv() {
var n1=document.calc.first.value; var n2=document.calc.second.value; result=n1/n2;
document.calc.res.value=result; }
12. Write a Javascript program to demonstrate all string handling methods.
Aim: To write a Javascript program to demonstrate all string handling methods. Program:
<html>
<head> </head>
<body bgcolor="orange">
<h2><b><u>String Handling Functions in Javascript</u></b></h2> <script language="javascript">
var str="B V Raju College";
document.write("<br><b>The String is:" + str + "</b><hr width=300 color=red align=left>");
document.write("<br><u><b>Using charAt() and charCodeAt() methods</b></u>");
document.write("<br>charAt(5)-->" + str.charAt(5)); document.write("<br>charCodeAt(5)-->" +
str.charCodeAt(5));
document.write("<br><hr width=300 color=red align=left>><u><b>Using indexOf() and lastIndexOf() methods</b></u>");
document.write("<br>indexOf('e')-->" + str.indexOf('e')); document.write("<br>lastIndexOf('e')-->" +
document.write("<br><hr width=300 color=red align=left>><u><b>Using toLowerCase() and toUpperCase()
methods</b></u>");
document.write("<br>toLowerCase()-->" + str.toLowerCase());
document.write("<br>toUpperCase()-->" + str.toUpperCase());
document.write("<br><hr width=300 color=red align=left>><u><b>Using substr() and slice() methods</b></u>");
document.write("<br>substr(1,9): " + str.substr(1,9)); document.write("<br>slice(4,10): " + str.slice(4,10)); </script>
</body> </html>
Output:
13. Write a Javascript program for validating form fields.
(Fields: User Name, Password, Confirm Password, Email ID and Phone Number). Login.html
<html>
<head>
<script language="javascript" type="text/javascript" src="validate.js"> </script>
</head>
<body bgcolor="#CDF314">
<table align="center" border="1" bgcolor="#ABCABC"> <form name="f1" action="Home.html" method="post">
<tr>
<th colspan="2" align="center">
<h2>REGISTRATION FORM</h2> </th> </tr> <tr> <th>User Name:</th> <td>
<input type="text" name="uname" placeholder="User Name" > </td> </tr> <tr> <th>Password:</th> <td>
<input type="password" name="pwd" placeholder="Enter Password"> </td> </tr> <tr> <th>Confirm Password:</th> <td>
<input type="password" name="cpwd" placeholder="Reenter Password"> </td> </tr> <tr> <th>Email ID:</th> <td>
<input type="text" name="email" placeholder="Enter Email ID"> </td> </tr> <tr> <th>Phone Number:</th> <td>
<input type="text" name="phone" placeholder="Enter Phone Number">
</td> </tr>
<tr>
<td colspan="2" align="center">
</td> </tr> </form> </table> </body> </html> Home.html <html> <body>
<h1 align="center">Hello Welcome User</h1> </body> </html> Validate.js function validate() { var uname=document.f1.uname.value; var pwd=document.f1.pwd.value; var cpwd=document.f1.cpwd.value; var email=document.f1.email.value; var atpos = email.indexOf("@"); var dotpos = email.lastIndexOf(".");
var phone=document.f1.phone.value;
if(uname=="") {
alert("User Name Can not be empty"); document.f1.uname.focus()
return false; }
else if(pwd=="") {
alert("Password Cannot be empty"); document.f1.pwd.focus();
return false; }
else if(pwd.length<6) {
alert("Password must be atleast 6 characters"); document.f1.pwd.focus();
return false; }
else if(pwd!=cpwd) {
alert("Password and Confirm Password must be equal"); document.f1.cpwd.focus();
return false; }
alert("Email ID Can not be empty"); document.f1.email.focus();
return false; }
else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length) {
alert("Not a valid e-mail address"); document.f1.email.focus();
return false; }
else if(phone=="") {
alert("Phone Number Can not be empty"); document.f1.phone.focus();
return false; }
else if(isNaN(phone) || phone.indexOf(" ")!=-1) {
alert("Phone Number must be numeric"); document.f1.phone.focus();
return false; }
else if (phone.length!=10)
{
alert("Phone number must be 10 digits"); document.f1.phone.focus();
return false; }
else {
return true; }
}
14. Write a Javascript program to demonstrate exception handling.
<html>
<head>
<title>Example on Exception Handling</title> </head>
<body bgcolor="#CDF357">
<h3>EXAMPLE ON EXCEPTION HANDLING</h3> <hr>
<p><b>Please input a number between 5 and 10</b></p> <form>
<input id="demo" type="text">
<button type="button" onclick="myFunction()">Test Input</button> </form>
<b><p id="message"></p></b>
<script language="javascript"> function myFunction() {
var x;
x = document.getElementById("demo").value; try
{
if(x == "") throw "empty";
if(isNaN(x)) throw "not a number"; x = parseInt(x);
if(x < 5) throw "too low"; if(x > 10) throw "too high"; if(x>=5 && x<=10)
{
alert("The number is:" + x); }
}
catch(err) {
} }
</script> </body>
</html>
Output1:
Output2:
15. Write a Javascript program to demonstrate all Array Object based methods.
<html>
<head>
<title>Example on Array Object Based Methods</title> </head>
<body bgcolor="#fdbace">
<h2>Example on Array Object Based Methods</h2> <hr width=430 align=left color=red>
<script language="javascript">
/* Using Join and Concat Methods */
document.write("<h3><u>Using JOIN and CONCAT methods</u></h3>"); var arr1=[10,20,30];
var arr2=[40,50,60];
document.write("<b>First Array Elements are----></b>" + arr1);
document.write("<br><b>arr1.join(':')---></b>" + arr1.join(":"));
document.write("<br><b>arr1.concat(arr2)----></b>" + arr1.concat(arr2)); document.write("<hr width=300 align=left color=green>");
/* Using POP and SHIFT Methods */
document.write("<h3><u>Using POP and SHIFT methods</u></h3>");
var arr=[10,20,30,40,50];
document.write("<b>The array elements are---></b>" + arr); arr.pop();
document.write("<br><b>After arr.pop()---></b>" + arr); arr.shift();
document.write("<br><b>After arr.shift()---></b>" + arr);
document.write("<hr width=300 align=left color=green>");
/* Using PUSH and UNSHIFT Methods */
document.write("<h3><u>Using PUSH and UNSHIFT methods</u></h3>");
var arr=[10,20,30,40,50];
document.write("<b>The array elements are---></b>" + arr); arr.push(60);
document.write("<br><b>After arr.push(60)---></b>" + arr); arr.unshift(5);
document.write("<br><b>After arr.unshift(5)---></b>" + arr);
document.write("<hr width=300 align=left color=green>");
/* Using SORT and REVERSE Methods */
document.write("<h3><u>Using SORT and REVERSE methods</u></h3>");
var arr=[1,9,8,5,7,2];
document.write("<b>The array elements are---></b>" + arr);
document.write("<br><b>After arr.sort()---></b>" + arr.sort()); document.write("<br><b>After arr.reverse()---></b>" + arr.reverse());
document.write("<hr width=300 align=left color=green>");
/* Using SLICE and SPLICE Methods */
document.write("<h3><u>Using SLICE and SPLICE methods</u></h3>");
var arr=[1,9,8,5,7,2];
document.write("<b>The array elements are---></b>" + arr);
document.write("<br><b>After arr.slice(1,4)---></b>" + arr.slice(1,4)); document.write("<br><b>After arr.slice(2,5)---></b>" + arr.slice(2,5));
document.write("<br><b>After arr.splice(2,2,'BVRICE','IIIBSc')---></b>" + arr);
document.write("<hr width=300 align=left color=green>");
</script> </body>
</html>
Output
Aim: To write a Javascript program to demonstrate Date and Window Objects.
<html>
<head>
<title>Built-in Objects in Javascript</title> </head>
<body>
<h2>Example on Built-in Objects in Javascript</h2> <hr width="450" color="red" align="left">
<script language="javascript">
document.write("<h3><u>Using Date Object</u></h3>");
var d=new Date();
document.writeln("<br><b>The date is:</b>" + d + "<br>"); document.writeln("<b>getDate():</b>" + d.getDate() + "<br>"); document.writeln("<b>getDay():</b>" + d.getDay() + "<br>"); document.writeln("<b>getMonth():</b>" + d.getMonth() + "<br>"); document.writeln("<b>getFullYear():</b>" + d.getFullYear() + "<br>");
document.writeln("<b>getTime():</b>" + d.getTime() + "<br>"); document.writeln("<b>getHours():</b>" + d.getHours() + "<br>"); document.writeln("<b>getMinutes():</b>" + d.getMinutes() + "<br>"); document.writeln("<b>getSeconds():</b>" + d.getSeconds() + "<br>"); document.writeln("<b>getMilliseconds():</b>" + d.getMilliseconds());
</script>
<hr width=450 color=red align=left> <h3><u>Using Window Object</u></h3> <b><u>1. window.open() method</u></b>
<br>Click the button to open a Google in a new browser window<br> <button onclick=openGoogle()>Open</button>
<script language="javascript"> function openGoogle() {
window.open("http://www.google.com"); }
</script>
<hr width=450 color=red align=left>
<b><u>2. setTimeout(),clearTimeout() and confirm() methods</u></b> <p>Click the first button to alert "Hello" after waiting 5 seconds.</p> <p>Click the second button to cancel alert before 5 seconds.</p>
<button onclick="myFunction()">Try it</button> <button onclick="myFunction1()">Stop alert</button>
var x;
function myFunction() {
x=setTimeout(function(){ alert("Hello");} ,5000); }
function myFunction1() {
var flag=confirm("Do you want to Cancel"); if(flag==true)
{
clearTimeout(x); }
} </script>
</body> </html>