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.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    radio button onClick not working, hopefully a simple fix?

    Hey I am trying to create a script that changes an image when a certain radio button is clicked, which should be pretty simple but I haven't written javascript in a long time so I am struggling... any help is appreciated, heres the code I've got:

    Code:
    <script language='JavaScript' type='text/javascript'>
    function changeImage(newImage)
    {
        if document.images['img_name'].src = eval(newImage + ".src");
    }
    image1 = new Image();
    image1.src = "images/pricing/avail_1.gif";
    
    image2 = new Image();
    image2.src = "images/pricing/avail_2.gif";
    </script>
    
    <input type="radio" onClick="changeImage('image1');" > </input> <br />
    <input type="radio" onClick="changeImage('image2');" > </input> <br />
    
    <img name="img_name" src="images/pricing/avail_1.gif">
    thanks

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the "if" supposed to do in function changeImage()?

    david_kw

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh, wow, it works now. thank you


  •  

    Posting Permissions

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