jQuery onchange/onfocus select box to display an image?

SoulieBaby picture SoulieBaby · Jun 12, 2009 · Viewed 90k times · Source

I need some help finding a jQuery plugin which will allow me to display an image preview from a select list of images - onfocus/onchange..

Example:

<select name="image" id="image" class="inputbox" size="1">
   <option value=""> - Select Image - </option>
   <option value="image1.jpg">image1.jpg</option>
   <option value="image2.jpg">image2.jpg</option>
   <option value="image3.jpg">image3.jpg</option>
</select>

<div id="imagePreview">
   displays image here
</div>

Has anyone come across something like this? I've tried searching for it to no avail..

Thank you!

Answer

Ben Blank picture Ben Blank · Jun 12, 2009

I'm not sure you need a plugin to deal with this:

$(document).ready(function() {
    $("#image").change(function() {
        var src = $(this).val();

        $("#imagePreview").html(src ? "<img src='" + src + "'>" : "");
    });
});