Click to See Complete Forum and Search --> : bgColor of a cell


doodler
05-09-2003, 03:20 PM
Take a lok at this script:

function notifyofdone(){
intrvl=0;
for(nTimes=0;nTimes<3;nTimes++){
intrvl += 200;
setTimeout("document.donecell.bgColor='#FF00FF';",intrvl);
intrvl += 200;
setTimeout("document.donecell.bgColor='#FFFFFF';",intrvl);
}
}
It changes a cell's bgcolor (like a blinker) to 2 colors.
In the body tag i have a onload event that calls this function, when i load the page in my IE browser (not sure about anything else) i get a "document.donecell is null or not an object" error (where donecell is the id of the cell i want to change the bgcolor of). What am i doing wrong?

khalidali63
05-09-2003, 03:32 PM
to reference an html element, you cn insert an id attribute and then reference using that in your case suppose the td or cell looks like this
<td id="td_id"></td>

now your javascript code may look like this

document.getElementById("td_id").style.backgroundColor='#FF00FF'

doodler
05-09-2003, 03:34 PM
i have already done waht you said about the id bit, but it didnt work because the reference i used returned the error (see above).

khalidali63
05-09-2003, 03:41 PM
The suggestion works fine,the problem might be in this function
setTimeout("
I have never applied javsscript code from setTimeout function,You might want to change your logic,call function from setTimeout and have the color changed in that function

doodler
05-09-2003, 03:43 PM
I have done it with slight modifications to the syntax. Thanks alot