I have an img tag and a select box
You can set onchange
event to the select
.
<select name="kitchen_color" id="kitchen_color" onchange="setImage(this);">
<option value="https://www.google.ru/images/srpr/logo4w.png">Google</option>
<option value="http://yandex.st/www/1.645/yaru/i/logo.png">Yandex</option>
<option value="http://limg.imgsmail.ru/s/images/logo/logo.v2.png">Mail</option>
</select><br />
<img src="" name="image-swap" />
Javascript:
function setImage(select){
var image = document.getElementsByName("image-swap")[0];
image.src = select.options[select.selectedIndex].value;
}
Example there
try this
<img src="" class="image-swap">
<select name="kitchen_color" id="kitchen_color" onchange="change_image()">
<option value="/static/imag1.jpg">Red</option>
<option value="/static/imag2.jpg">Black</option>
<option value="/static/imag3.jpg">White</option>
</select>
$(document).ready(function(){
$('.image-swap').attr("src",$('#kitchen_color').val());
})
function change_image(){
$('.image-swap').attr("src",$('#kitchen_color').val());
}
use a change function on your select list
$('#kitchen_color').change( function() {
$("#imgid").attr("src","new src value");
});
$(document).ready(function(){
$("#kitchen_color").change(function(){
$("img[name=image-swap]").attr("src",$(this).val());
});
});
Use above code.