View Full Version : A problem with OnMouseOver...
$0.05$
04-21-2003, 03:19 PM
okay, my script looks like this
function change(imgName, image1, image2) {
document.details.src = image2;
document.imgName.src = image1;
}
function changeBack(imgName, image1) {
document.details.src = 'Images/placeholder.gif';
document.imgName.src = image1;
}
and my call looks like this
<a href="resume.htm" onMouseOut="changeBack('Resume', 'Images/1-1.gif')" onMouseOver="change('Resume','Images/1-2.gif','Images/resume.gif')">
but the problem that i get, is that document.imgName is null, or not an object
does anyone know why this would be happening?
beetle
04-21-2003, 03:33 PM
That's because the images collection isn't directly mapped to the document object (the way forms and frames are)
So, you'd need a different retrieval method
document.images['details']
document.images[imageName]
Should work. However, moving foward, your images should have ids and not names, in which case you could also use
document.getElementById('details')
document.getElementById(imageName)
cheesebagpipe
04-21-2003, 04:15 PM
That's because the images collection isn't directly mapped to the document object (the way forms and frames are)It is, actually...the problem here isn't exposed references but that old dot syntax vs. string (hash) referencing thing.
function change(imgName, image1, image2) { //imgName as string
document.details.src = image2;
document.imgName.src = image1; //now as identifier
}
You'll need to use:
document[imgName].src = image1;
...to properly 'plug in' a string (associative array) reference. Don't forget to name the image; or just id it as beetle suggested and forget the whole (old) thing. :rolleyes:
beetle
04-21-2003, 04:57 PM
Oh. I guess I never used it that way. Personally, I think all those mappings are stupid. I almost always stick to the collections.
brothercake
04-21-2003, 05:22 PM
Originally posted by beetle
Oh. I guess I never used it that way. Personally, I think all those mappings are stupid. I almost always stick to the collections.
they're also inefficient - the interpretor has to go that extra step to map the reference to each relevant collection until it finds a match. Much better to specify the collection yourself.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.