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? Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/ 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 Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-685270 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 Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-685437 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. Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-686434 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> Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-686449 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. Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-686545 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> Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-686547 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 Link to comment https://forums.phpfreaks.com/topic/131898-solved-radio-onclick/#findComment-686552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.