Click to See Complete Forum and Search --> : Trouble with a script in NS6 and 7


JackTheTripper
05-08-2003, 05:49 PM
This script is supposed to wait until the page is loaded, then change the image in the div to an animated gif. It works fine in IE but not ButtScrape 6 or 7. What am I missing here.

Thanks.

<html>
<script>

function runYouthAd() {
document.getElementById('youth_ad').src= "images/index/youthAd_b.gif"
}

</script>

</head>

<body onLoad="runYouthAd();">


<div id="youthAd" style="position:absolute; left:0px; top:1; z-index:7; visibility: inherit">
<img src="images/index/image1.gif" name="youth_ad">
</div>

</body>
</html>

khalidali63
05-08-2003, 05:58 PM
Take a look at this line

document.getElementById('youth_ad').src= "images/index/youthAd_b.gif"

you are trying to get a reference to the image element by id

Can you see id attribute here
<img src="images/index/image1.gif" name="youth_ad">

Cus I can't..

:D

JackTheTripper
05-08-2003, 06:06 PM
Ich! Crap! I was thinking name= would be good enough. Damn it! See, that's why I like IE. It's smart enough to figure out what the heck I'm trying to do, even when I don't tell it right.

Thanks.

JackTheTripper
05-08-2003, 06:20 PM
Originally posted by Dave Clark


document.images['youth_ad'].src = "images/index/youthAd_b.gif"

Dave

And this works in IE5+ and NS6+? I didn't think it did.

One more Q... Can Name and ID be the same? i.e.

<img src= "foo.gif" name = "blah" id = "blah">

Thanks

JackTheTripper
05-08-2003, 06:33 PM
Cool. Thanks. Maybe it was 4.7 that doesn't support it? Oh well, working now. thanks again.