Professional Documents
Culture Documents
Java Script
Java Script
Practical No : 8
Create a web page in HTML having a white background and two Button Objects.
Write code by using JavaScript such that
When the mouse is placed over the first button object without clicking, the color of the
background of the page should change after every few seconds.
There should at least be 7 different and visibly distinct background colors excluding
the default color.
Javascript function:
setTimeout :
It executes a block of code after
specific time.
Javascript Events :
Onmouseover
Onclick
3
XP
Syntax:
Example:
setTimeout(“p1()”,2000)
4
Javascript Program Layout: XP
<html><head><title> JS</title>
<script language = “javascript”>
. . . JS functions…
</script>
</head>
<body>
Buttons, textboxes
</body></html>
5
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
<body>
<br>
<h1> This is Event Driven Client Side Script </h1>
<form name=f1>
<input type="button" value=" place your cursor " onmouseover="p1()">
<input type="button" value=" Click Here for status message " onClick="StatusBar()" >
</form>
</body>
</html>
XP
7
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p1()
{
document.bgColor="BLUE";
window.setTimeout("p2()",2000);
}
XP
9
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p1()
{
document.bgColor="BLUE";
window.setTimeout("p2()",2000);
}
function p2()
{
document.bgColor="PINK";
window.setTimeout("p3()",2000);
}
XP
11
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p1()
{
document.bgColor="BLUE";
window.setTimeout("p2()",2000);
}
function p2()
{
document.bgColor="PINK";
window.setTimeout("p3()",2000);
}
function p3()
{
document.bgColor="BLACK";
window.setTimeout("p4()",2000);
}
XP
13
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p4()
{
document.bgColor="YELLOW";
window.setTimeout("p5()",2000);
}
XP
15
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p4()
{
document.bgColor="YELLOW";
window.setTimeout("p5()",2000);
}
function p5()
{
document.bgColor=“ORANGE";
window.setTimeout("p6()",2000);
}
XP
17
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p4()
{
document.bgColor="YELLOW";
window.setTimeout("p5()",2000);
}
function p5()
{
document.bgColor=“ORANGE";
window.setTimeout("p6()",2000);
}
function p6()
{
document.bgColor=“RED";
window.setTimeout("p7()",2000);
}
XP
19
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p6()
{
document.bgColor=“RED ";
window.setTimeout("p7()",2000);
}
function p7()
{
document.bgColor=“GREEN";
window.setTimeout("p1()",2000);
}
XP
21
XP
<html>
<head>
<title> Event driven client side script </title>
<script language="javascript">
function p6()
{
document.bgColor=“RED ";
window.setTimeout("p7()",2000);
}
function p7()
{
document.bgColor=“GREEN";
window.setTimeout("p1()",2000);
}
function StatusBar()
{
window.status = "This is event driven program";
}
XP
StatusBar
23