I am currently working with radio buttons to display an image when clicked on with the help of javascript. The problem is that I am not getting result displayed when clicking a radio button. The code below shows that i am using a function and then triggering the even when click. Is there something the code is missing? or Is there a better approach to this? This an Example
Thank you
Javascript
<script>
function check_value() {
function check_value(fieldvalue) {
switch (fieldvalue) {
case 1:
document.getElementById("imagedest").innerHTML = "<img src='images/bike1.jpg'>";
break;
case 2:
document.getElementById("imagedest").innerHTML = "<img src='images/bike2.jpg'>";
break;
case 3:
document.getElementById("imagedest").innerHTML = "<img src='images/bike3.jpg'>";
break;
}
}
</script>
HTML
<form name="builder">
<input type="radio" name="field" value="one" onclick='check_value(1)'/> KAWASAKI KX 450F<br />
<input type="radio" name="field" value="two" onclick='check_value(2)'/> 2010 Yamaha Road Star S<br />
<input type="radio" name="field" value="three" onclick='check_value(3)'/> Aprilia RSV4<br />
</form>
<div id="imagedest"></div>
What is the purpose of the extra
function check_value() {preceding the code? It seems its purpose is to stop your code from working and therefore prompt you to ask this question.Remove it, and all will be well.