"Dica" <ge*****@hotmail.com> wrote in message
news:os********************@rogers.com...
"Lee" <RE**************@cox.net> wrote in message
news:ct*********@drn.newsguy.com... Dica said: >
>this works:
>document.all[sResponseDivID].style.visibility = 'hidden';
>
>this doesn't
>setTimeout("document.all[sResponseDivID].style.visibility = 'hidden'",1000); >
>looks like sResponseDivID isn't recognized. what's the problem?
sResponseDivID has a value at the time and in the scope that you
call setTimeout, but that string is parsed as a Javascript expression
at another time and in another scope. Instead of putting the name of
the variable in the string, put the value in it:
setTimeout("document.all["+sResponseDivID+"].style.visibility =
'hidden'",1000)
tks lee, but still doesn't work. i'm still getting
"document.all[...].style
is null or not an object". this is the full code:
setTimeout("document.all["+sResponseDivID+"].style.visibility =
'hidden'",1000)
The problem is that you are sustituting the _value_ of sResponseDivID
into the square brackets, and that value is not quoted.
<div id="test">TEST</div>
<script type="text/javascript">
var sResponseDivID = 'test';
setTimeout("document.all['" + sResponseDivID + "'].style.visibility =
'hidden'", 1000);
</script>
Note the single quotes immediately inside the square brackets. This
ensures that setTimeout() is evaluating the following:
document.all['test'].style.visibility = 'hidden';
and not:
document.all[test].style.visibility = 'hidden';
Please also note that if sResponseDivID must be defined as part of the
global object (ie - not in a function), because it _must_ be in scope
when the setTimeout() executes the code.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq