Click to See Complete Forum and Search --> : re: images are "undefined"


luds
05-07-2003, 06:52 PM
Hi

I'm trying to get a simple rollover button to work... but I think I'm missing something!

the code is...

<script language="JavaScript1.1" type="text/JavaScript">
<!-- Hide from older browsers

if(document.images)
{
upHistory = new Image
downHistory = new Image

upHistory.scr = "navbars/buttons/historyup.gif"
downHistory.src = "navbars/buttons/historydown.gif"
}

else
{
upHistory = ""
downHistory = ""
document.historybut = ""
}

// End hiding script -->
</script>

<body>
<a href="backgroundhtml.htm"
onMouseOver="document.historybut.src=downHistory.src"
onMouseOut="document.historybut.src=upHistory.src">

<img src="navbars/buttons/historyup.gif" width="158" height="47" name="historybut" alt="See how the National Mozart Competition started"></a>

The message in both IE and Netscape javascript errors is "uphistory is not defined" and "downHistory" is not defined.

Thanks

luds

khalidali63
05-07-2003, 07:02 PM
Try this coding pattern...
http://68.145.35.86/skills/javascripts/SimpleImageSwap.html

havik
05-07-2003, 07:30 PM
Shouldn't you use brackets to show that Image is a function? I haven't tested this yet so I'm not sure it works. Also, you spelt the source wrong for uphistory (.src not .scr)

so something like this:

upHistory = new Image()
downHistory = new Image()

upHistory.src = "navbars/buttons/historyup.gif"
downHistory.src = "navbars/buttons/historydown.gif"

Havik

EDITED: actually, this post probably won't help any more. I'll look at it more extensively if khalidali's link doesn't help.

havik
05-07-2003, 07:42 PM
Try this... (works for NS6 and IE) and you can edit it to work for you.

Havik

NS6 = (document.getElementById&&!document.all)
IE = (document.all)

if(document.images) {
IMAGE = new Image()
IMAGE.src = "navbars/buttons/historyup.gif"

IMAGE_on = new Image()
IMAGE_on.src = "navbars/buttons/historydown.gif"

}

function rolloverOn(name) {
if((IE || NS6) && preloaded == true)
document[name].src = eval(name + "_on.src");
}

function rolloverOff(name) {
if((IE || NS6) && preloaded == true)
document[name].src = eval(name + ".src");
}

Then this in your link:

<a href="backgroundhtml.htm" onmouseover="rolloverOn('IMAGE');" onmouseout="rolloverOff('IMAGE');">
<img src="image" border="0" name=IMAGE alt=""></a>

luds
05-07-2003, 07:44 PM
Grrrrr.. mutter grumble....

Would you believe that I checked the instances of src at least 5 times!!!

Cheers!
Just goes to show what a fresh pair of eyes can do!

Everything working here now!

Thanks to both of you for your time and help! :¬)

luds

havik
05-07-2003, 07:45 PM
Alright, just ignore my last post then :D

Havik

luds
05-07-2003, 07:54 PM
lol Havik!

I never ignore replies!!!!

Haven't checked my original script in netscape yet!!

Thanks again m8

luds