I am currently working with radio buttons and checkboxes to display images using javascript. To be specific: I ran into a problem while working with checkboxes and displaying images. Using the radio buttons for this category, only one image will be displayed. But with checkboxes you need to display more than one image. For example, a user may check the jacket and glove box and both images will be displayed.
How can I format a function to display multiple images when I click the buttons? EXAMPLE
Js
<script language="JavaScript" type="text/javascript">
function check_value(val, id, type) {
var el = document.getElementById("imgBox" + id);
if (val>0 && val<4) {
el.src = "images/"+ type + val + ".jpg";
el.style.display = "";
}
}
</script>
HTML
<h2>Choose a bike</h2>
<form name="builder">
<input type="radio" name="field" value="1" onclick='check_value(1, 1, "bike")'/> KAWASAKI KX 450F<br />
<input type="radio" name="field" value="2" onclick='check_value(2, 1, "bike")'/> 2010 Yamaha Road Star S<br />
<input type="radio" name="field" value="3" onclick='check_value(3, 1, "bike")'/> Aprilia RSV4<br />
</form>
<img id="imgBox1" src="#" style="display:none">
<h2>Choose a tire</h2>
<form name="tire">
<input type="radio" name="field" value="1" onclick='check_value(1, 2, "tire")'/> Michelin Pilot Road 3 Tires<br />
<input type="radio" name="field" value="2" onclick='check_value(2, 2, "tire")'/> Dunlop Roadsmart Sport-Touring Tires<br />
<input type="radio" name="field" value="3" onclick='check_value(3, 2, "tire")'/> Pirelli Scorpion Trail Tires<br />
</form>
<img id="imgBox2" src="#" style="display:none">
<h2>Choose Accesories</h2>
<form name="tire">
<input type="checkbox" name="field" value="1" onclick='check_value(1, 3, "accesories")'/> Chrome Front Plate<br />
<input type="checkbox" name="field" value="2" onclick='check_value(2, 3, "accesories")'/> Jacket<br />
<input type="checkbox" name="field" value="3" onclick='check_value(3, 3, "accesories")'/> Gloves
</form>
<img id="imgBox3" src="#" style="display:none">
source
share