switching images. please help

M

Mel

i have a +.gif image and i want to change it to -.gif image when user
clicked on it.

so i have something like:
img.src=(img.src == "+.fig" ? "-.gif" : "+.gif");

that works on the first click, but it never changes there after.

can someone please come to ma rescue ?????

thanks a whole bunch

a lil code is highly appreciated
 
L

Lee

Mel said:
i have a +.gif image and i want to change it to -.gif image when user
clicked on it.

so i have something like:
img.src=(img.src == "+.fig" ? "-.gif" : "+.gif");

that works on the first click, but it never changes there after.

can someone please come to ma rescue ?????

This isn't chat. When you're asking for help, please have
the courtesy to make the extra effort required to use your
shift key.

Debugging 101: Alert(img.src) and you'll see why it's not working.
 
R

Randy Webb

Mel said the following on 3/13/2006 6:07 PM:
i have a +.gif image and i want to change it to -.gif image when user
clicked on it.

so i have something like:
img.src=(img.src == "+.fig" ? "-.gif" : "+.gif");

alert(img.src)

It won't be what you expect it to be. Meaning, it wont be "-.gif" or
"+.gif" but rather it will be a fully qualified URL to the image.
that works on the first click, but it never changes there after.

Because that is what you coded.
can someone please come to ma rescue ?????

Is your ma in danger? Call the law.
thanks a whole bunch

a lil code is highly appreciated

I gave you some above, but here is a URL that will do you more good than
a "lil code":

<URL:
http://groups.google.com/group/comp...tathome+indexOf+image&rnum=1#52eb4eaf735fe73c
 
R

Randy Webb

Lee said the following on 3/13/2006 6:18 PM:
Mel said:

This isn't chat. When you're asking for help, please have
the courtesy to make the extra effort required to use your
shift key.

Debugging 101: Alert(img.src) and you'll see why it's not working.

Object Expected <g>
 
M

Mel

ok, lets try again;

I have the following:
img.src = (img.src == 'http:/blah/images/+.gif' ?
'http:/blah/images/-.gif' : 'http:/blah/images/+.gif'

I am very very sorry to try to cut corners.

Can you now tell me how to flip the image src from "+.gif" to "-.gif" ?

thanks
 
S

Stephen Chalmers

Mel said:
i have a +.gif image and i want to change it to -.gif image when user
clicked on it.

so i have something like:
img.src=(img.src == "+.fig" ? "-.gif" : "+.gif");

that works on the first click, but it never changes there after.

img.src=img.src.match( '+.gif' ) ? '-.gif' : '+.gif' ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top