Closed Thread Icon

Topic awaiting preservation: image-change script Pages that link to <a href="https://ozoneasylum.com/backlink?for=24291" title="Pages that link to Topic awaiting preservation: image-change script" rel="nofollow" >Topic awaiting preservation: image-change script\

 
Author Thread
slim___shady
Nervous Wreck (II) Inmate

From: canada
Insane since: Aug 2002

posted posted 12-04-2004 08:05

I'm missing something somewhere with this simple image-switching script. What I am trying to do is to change the + into a - when it is clicked on, and back to + when it is clicked again.

I'm sure someone will see what's wrong with the code. I can't.
Please help.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-04-2004 08:36

It's possible that the src property of the image isn't pre-set (that is, reading from it and comparing it to "plus.gif" might not work as expected).

Set a boolean and toggle it instead.


 

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

posted posted 12-04-2004 08:38

Try this:

<img ... onclick="toggle(this);">

code:
function toggle(elm){
elm.src=elm.src!='plus.gif'?
'plus.gif':
'minus.gif';
}




Note that it is possible that browsers read out the actual resulved uri instead of the relatiove uri. THere's not set rule for whether on behavior or the other is the one that should be used in HTML. (There are rules for XML, but that's another story...)
--
var Liorean = {
prototype: CSSGuru.prototype,
abode: "http://web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

(Edited by liorean on 12-04-2004 08:40)

slim___shady
Nervous Wreck (II) Inmate

From: canada
Insane since: Aug 2002

posted posted 12-05-2004 01:34

thanks for replying slime and liorean. I couldn't get your suggestions to work but I figured out a workaround using display:none and display:inline. Just thought I would let you know.

« BackwardsOnwards »

Show Forum Drop Down Menu