0

I had a given a assignment of java script as
to form a script that changes the background image of the document after equal interval of time.as i am a beginner to programming I had formed a script that should change background and a loop stated for image name to be taken from the file with common extension.In all there are 27 image which should be displayed in serial number.
but not working
here is the code

<html>
<script language="javascript">
function f1()
{
var n;
window.setTimeout("f1()",1200);
for (n=1;n<27;n++)
document.body.background=(n+".png");
}

</script>
<body>
<input type="button" onMouseover="f1()" value="Change Document Color"><p>
</body>
</html>
2
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by dendenny01
1

Use setInterval:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">

<html>
<head>
<title></title>

<script>

var timeout = setInterval(function(){
	document.body.background = 'Images/image_' + Math.floor(Math.random() * 9) + '.png';
}, 1200);

</script>

</head>
<body>


</body>
</html>
0

I had Tried Using this Code but the Images which are displaying are at random

The image has to be in serial

1

Is this your homework, if so I want the credit:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">

<html>
<head>
<title></title>

<script>

var i = 0;

var timeout = setInterval(function(){

	if(i === 27){
		i = 0;
	}
	else{
		i++;
	}

	document.body.background = 'Images/image_' + i + '.png';
}, 1200);

</script>

</head>
<body>


</body>
</html>
Votes + Comments
Thanxx a lot sir for your help
0

Thank you sir Its works Great.
My Teacher will be amazed by this code
and all the credit goes to you

and you explain me what was going wrong with my original code
please

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.