Shoutbox

JavaScript Help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: JavaScript Help (/showthread.php?tid=41990)

JavaScript Help by Dempsey on 04-05-2005 at 04:31 PM

Hi All,

I have an image (lets say ImageA) and when its clicked i want it to change to ImageB.

But then if ImageB is clicked it goes back to ImageA.

I know how to chnage the image the first time, but not sure how to check if its already been changed to choose which image to change it too.

I think i need to set a boolean value to keep track, but i don't know much javascript so can someone help?


RE: JavaScript Help by Stigmata on 04-05-2005 at 04:35 PM

code:
function changepic ()
if (document.Image.src =="path to image a") {
document.Image.src = "path to image b";
}
else{
document.Image.src = "path to image a";
}


code:
onclick="document.image.src = changepic(); return false;"


something like that?

RE: JavaScript Help by Dempsey on 04-05-2005 at 04:43 PM

[n00b mode]  do i have to change Image to the image name?  [/n00b mode]


RE: JavaScript Help by Joe on 04-05-2005 at 04:47 PM

"path to image a"

fill that in with the path to the image and do the same with the other ones


RE: JavaScript Help by TheGeek on 04-05-2005 at 04:48 PM

html:

code:
<img src="image1.gif" id="Image" onclick="document.image.src = changepic(); return false;">

javascript:
code:
function changepic ()
if (document.Image.src =="path to image a") {
document.getElementByID("Image").src = "path to image b";
}
else{
document.getElementByID("Image").src = "path to image a";
}

I'm a little bit rusty on the JS, but i think it should be like this.
RE: JavaScript Help by Dempsey on 04-05-2005 at 04:49 PM

yea ive chnage the paths, but i wasnt sure if i have to change

code:
docuemnt.image.src
to
code:
docuement.imagename.src

RE: JavaScript Help by TheGeek on 04-05-2005 at 04:53 PM

i don't think docuement.imagename.src will work...


RE: JavaScript Help by Stigmata on 04-05-2005 at 04:54 PM

:) yes

also if its in a table etc you need to add its name after document