Forum Moderators: open

Message Too Old, No Replies

JS image swap woes

I can do it ... then I can't

         

aceholleran

2:44 pm on Sep 27, 2003 (gmt 0)

10+ Year Member



Yes, I can do a JS image rollover via an intra-anchor link, but I want to use true JS.

The original image is a solid blank box ("blanker.gif"); the rollovers are "number1.gif","number2.gif" and so on.
This seems so easy, but I keep getting "'bloc' is not an object" errors.

The script:

function subnum(x) {
document.bloc[x].src="number"+x+".gif"}

***********************************************
The html in-body code:

<a href="#" onmouseover="subnum(1)"><img src="blanker.gif" border="0" width="24" height="28" alt="" name="bloc1">

<a href="#" onmouseover="subnum(2)"><img src="blanker.gif" border="0" width="24" height="28" alt="" name="bloc2">

etc.

************************************************
Can't I see the forst for duh treez?

Ace in CT

tedster

6:08 pm on Sep 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not a js expert by any means, but here's what I think is going on.

bloc[x] indicates element x of an array named "bloc" -- the error is telling you that there is no such object as an array named bloc, and in the code you posted, there isn't.

garann

5:41 pm on Sep 29, 2003 (gmt 0)

10+ Year Member



If you're able to change the name attributes in your images to ids, this function should accomplish what you want..

function subnum(x) { 
document.getElementById("bloc" + x).src="number"+x+".gif"
}

aceholleran

6:41 pm on Sep 29, 2003 (gmt 0)

10+ Year Member



This worked perfectly--thank you.

Ace