Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery onchange/onfocus select box to display an image?

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!

like image 374
SoulieBaby Avatar asked Jun 12 '09 00:06

SoulieBaby


1 Answers

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 + "'>" : "");
    });
});
like image 95
Ben Blank Avatar answered Oct 26 '22 22:10

Ben Blank