Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change an image when you click on a link

    Can someone help me out here. On my site I would like to make it so when you click on a band member's name, it changes the can on the left hand side (in a frame) to a picture of them. So for example you click on Name1 and it changes the picture to images/name1.jpg But I would like to have it reset to the can when you leave the band page. Viewable in at least IE and preferably firefox too.. Thanks in advance!
    PS Just saw the other post, not trying to double post, but i thought this was a bit different... And is it possible to double-click on the name to change the pic, instead of just a single click?
    Last edited by SCSS; 06-01-2005 at 01:30 AM. Reason: editing... :P

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Sydney, NSW, Australia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this should do the trick;

    Code:
    <img src="old.gif" name="changeMe">
    
    <a href="#" onclick="return false" ondblclick="document.images['changeMe'].src='new.gif'">Change Image</a>

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Will this work for frames too? because the can is in a frame to the side, and the names are in a different frame thanks for the reply too.

  • #4
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    if it doesnt post the code, or atleast the frame names and image names

    i've done it before so i know it works
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doesnt work Here's the code for the band page: (lots of stuff has been left out so it doesnt take up a few pages...)

    Code:
    <a href="#" onclick="return false" ondblclick="document.images['changeMe'].src='images/jordan.jpg'">Jordan:</a>
    frame stuff with names:
    Code:
    <frameset rows="38%,*" border="0">
        <frame name="switch" src="switch.html" frameborder="0" noresize>
            <frameset cols="62%,*" border="0">
            <frame name="main" src="main.html" frameborder="0" noresize>
            <frame name="can" src="can.html" frameborder="0" noresize>
        </frameset>
    </frameset>
    can frame:
    Code:
    <img src="images/can.jpg" name="changeMe">
    Also, will the image change back when you leave the band page? if not, how can I make it that way?

  • #6
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    I would do something like this:

    Code:
    <img src="images/can.jpg" id="changeMe">
    
    ...
    <a href="#" onclick="return false" ondclick="document.getElementByID(changeMe).src='images/jordan.jpg'">Jordan:</a>
    that may not work but its late and i'm tired... we'll look at it in the morn
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #7
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tried it, but no cigar... I get a "changeMe is undefined" error... Any ideas?
    EDIT I only get this error when using ondblclick="blahblahblah" nothing happens with ondclick="blahblahblah"

  • #8
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    getElementById('changeme')

    don't forget the quotes

  • #9
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    haha I just noticed that too! But now i get "Error: object doesn't support this property or method."
    Hmm

  • #10
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hm...the only thing i see is that you have a typo..

    ondclick="document.getElementByID(changeMe)....

    onclick=....

    don't know if copied this straight from your code, that could be it

  • #11
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the thing:

    Code:
    <a href="#" onclick="return false" ondclick="document.getElementByID('changeMe').src='images/jordan.jpg'">Jordan:</a>
    When I use that, nothing happens when I double click.

    When I use this:
    Code:
    <a href="#" onclick="return false" ondblclick="document.getElementByID('changeMe').src='images/jordan.jpg'">Jordan:</a>
    I get the error when I double click. am i missing something?

  • #12
    New Coder
    Join Date
    Feb 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try..

    <a href="#" ondblclick="return false;document.getElementByID('changeMe').src='images/jordan.jpg'">Jordan:</a>

    To be honest i've never done an image swap using this method, however, it does look like it should work. I have always used the javascript method that someone suggested at the beginning using the name property.

  • #13
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Again, it doesnt work. I even tried using onClick instead of ondblclick, but still nothing. Any other ideas guys?

  • #14
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    hehe you know what really aggravates me... i know the solution is simple!

    just so i get it right.
    - you want to onclick open a link and change a picture
    - you want the picture to revert back when you...?
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #15
    New Coder
    Join Date
    Mar 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well onclick or ondblclick. Either way, yes thats exactly what I want to do. I aswell have a feeling that its gonna be a really simple solution, but sometimes theyre the hardest to come up with!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •