Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Swap image on clicking a link

Question posted by: dougawells@gmail.com (Guest) on June 27th, 2008 07:16 PM
There are probably lots of good examples that I haven't found yet. I
want a link on a page to swap out two or three images that are on the
same page. Can someone please point me towards an example? I'm used to
doing this in Flash, not in HTML and Javascript.
Thanks
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Ed Jay's Avatar
Ed Jay
Guest
n/a Posts
June 27th, 2008
07:16 PM
#2

Re: Swap image on clicking a link
Join Bytes! scribed:
Quote:
Originally Posted by
>There are probably lots of good examples that I haven't found yet. I
>want a link on a page to swap out two or three images that are on the
>same page. Can someone please point me towards an example? I'm used to
>doing this in Flash, not in HTML and Javascript.
>Thanks


Google 'swap images'. There's a bunch. Then use onClick to call whichever
function you choose to use.

Ed Jay (remove 'M' to reply by email)

--
Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info

Roderik's Avatar
Roderik
Guest
n/a Posts
June 27th, 2008
07:16 PM
#3

Re: Swap image on clicking a link
Join Bytes! schreef:
Quote:
Originally Posted by
There are probably lots of good examples that I haven't found yet. I
want a link on a page to swap out two or three images that are on the
same page. Can someone please point me towards an example? I'm used to
doing this in Flash, not in HTML and Javascript.
Thanks


First hit from Google (http://www.devx.com/tips/Tip/13653):

<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript>
intImage = 2;
function swapImage() {
switch (intImage) {
case 1:
IMG1.src = "http://www.microsoft.com/library/toolbar/images/mslogo.gif"
intImage = 2
return(false);
case 2:
IMG1.src =
"http://msdn.microsoft.com/msdn-online/start/images/msdn-logo.gif"
intImage = 1
return(false);
}
}
</SCRIPT>
</HEAD>
<BODY>
<IMG id="IMG1" name="IMG1"
src="http://www.microsoft.com/library/toolbar/images/mslogo.gif"
onclick="swapImage();">
</BODY>
</HTML>

The code is a bit old fashioned (there should be a type for the script
and it should be hidden somewhat from the html IMO) but it is prob. easy
to adjust it. Of course you could also choose to use the hover event or
any other.

--
http://www.archytas.nl/
webdesign, internet applicaties, internetgestuurde elektronica

 
Not the answer you were looking for? Post your question . . .
183,969 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors