Background color change in a loop !! - loop to change background color dosent seem to work...

They have: 5 posts

Joined: Aug 1999

Hi

i have tried to make a function which will chang the background for a couple of times... the code is given below.
initially without the alert box there is only one change of color and not five

<html>
<head>
<title>trying time out</title>
<script Language="JavaScript">
<!--
var y=00000;

function callchangecolor()
{ var x=0;
for(;x<6;x++)
{
//setTimeout(" ",5000);
document.bgcolor=y;
document.write("<br><center><h1>the value of y "+y+"..<\/h1><\/center>");
//alert("checking");
y=y+54632;
}
}

//-->
</script>
</head>

<body>
<a href="javascript:callchangecolor()">click here</a>
</body>
</html>

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

This one works, but it's not quite the same thing you were trying to do. The writing to the page seemed to be somehow confusing the script it seems...

<html>
<head>
<title>trying time out</title>
<script Language="JavaScript">
<!--
var y=00000;
function callchangecolor()
{
var x=0;
for(x==0;x<6;x++)
{
document.bgColor=y;
alert("the value of y "+y+".."+;
//alert("checking"+;
y=y+54632;
//setTimeout("callchangecolor()",5000+;
}
}
//-->
</script>
</head>
<body>
<a href="javascript:callchangecolor()">click here</a>
</body>
</html>

----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.