Click to See Complete Forum and Search --> : ok, this is driving me nuts...


Greelmo
05-17-2003, 10:57 PM
here is my code for a simple backgroud changing thing... im just trying to fully understand the settimeout() method. I don't quite have it yet.

<html>
<head>
<title>JavaScript Alternating Backgrounds</title>
<SCRIPT LANGUAGE="JavaScript">
function fncback()
{
dexter=setTimeOut("fncgo()", 500);
}
function fncgo()
{
if(document.bgColor=="white"){
document.bgColor="red";}
else{
document.bgColor="white";}
}
</script>
</head>
<body onLoad="fncback();">
<font color=red size=7>hello</font>
</body>
</html>

khalidali63
05-17-2003, 11:02 PM
this statement

setTimeOut("fncgo()", 500);

should be

setTimeout("fncgo()", 500);

JavaScript is case sensitive language

Greelmo
05-17-2003, 11:05 PM
okay, so i had the funtion correct but i didn't make the'o' lowercase. HAHA. aint that a bummer?

khalidali63
05-17-2003, 11:07 PM
Welcome to the JavaScript programming..lol

Greelmo
05-17-2003, 11:13 PM
okay, so i have one more question to ask you... how can i make it loop so that it does it constantly?

khalidali63
05-17-2003, 11:14 PM
you mean infinite loop..that never stops?

Greelmo
05-17-2003, 11:14 PM
yupers

khalidali63
05-17-2003, 11:18 PM
I am hoping that you'd wnat this to take place after an equal number of seconds,,,say you want to chagnet the color after every scond....

just add this line in your function that changes the color,it will run it for everrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr....


}
function fncgo()
{
if(document.bgColor=="white"){
document.bgColor="red";}
else{
document.bgColor="white";}
dexter=setTimeout("fncgo()", 1000);
}

now after every 1 second this function will be called,
you can set
clearTimeout(dexter)
to stop the setTimeout loop

Greelmo
05-17-2003, 11:20 PM
thanks a million

khalidali63
05-17-2003, 11:21 PM
You are most welcome..:)

Dragons_Bane
05-18-2003, 12:49 PM
Wouldn't that get hard on the eyes :) lol :confused: :cool:

Now I'm just having fun