Jump to content

[SOLVED] Radio onclick


beansandsausages

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.