beansandsausages Posted November 8, 2008 Share Posted November 8, 2008 Hey, I am trying to make a form where if you click a value via a radio button how would i get it to change a image? Quote Link to comment Share on other sites More sharing options...
webster08 Posted November 8, 2008 Share Posted November 8, 2008 http://www.google.com/search?hl=en&q=change+image+src+with+javascript&btnG=Google+Search Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted November 8, 2008 Author Share Posted November 8, 2008 http://www.google.com/search?hl=en&q=change+image+src+with+javascript&btnG=Google+Search Tried that but got loads of confusing scripts lol. ill try your link Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 10, 2008 Share Posted November 10, 2008 Could you please list at least a little code. Otherwise you're just asking for someone to write your code for you, and that's kinda rude. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 10, 2008 Share Posted November 10, 2008 Try this: <script type="text/javascript"> function changeImg(image){ document.getElementById('myImg').src = image; } </script> <div> <input type="radio" onclick="changeImg('/images/image1.jpg');" /> <input type="radio" onclick="changeImg('/images/image2.jpg');" /> <input type="radio" onclick="changeImg('/images/image3.jpg');" /> </div> <div> <img id="myImg" src="" /> </div> Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted November 10, 2008 Author Share Posted November 10, 2008 Thank you TLG, Just a slight problem though if there in no radio boc CHECKED you get the broken image image, i have tried to set one of the radio boxed to CHECKED in hope it would load the checked image but no such luck, Any ideas? Thank you again. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 10, 2008 Share Posted November 10, 2008 Try this then: <script type="text/javascript"> function changeImg(image){ document.getElementById('myImg').innerHTML = "<img src='"+image+"' alt='' />"; } </script> <div> <input type="radio" onclick="changeImg('/images/image1.jpg');" /> <input type="radio" onclick="changeImg('/images/image2.jpg');" /> <input type="radio" onclick="changeImg('/images/image3.jpg');" /> </div> <div id="myImg"></div> Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted November 10, 2008 Author Share Posted November 10, 2008 Thank you. i owe you both a beer Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.