0

I currently have this here working..

$(document).ready(function() {
   $("#image").change(function() {
     $("#imagePreview").empty();
        $("#imagePreview").append("<img src=\"" + $("#image").val()  + "\" />");
   });
 });


<select name="image" id="image" class="inputbox" size="1">
   <option value="imageall.jpg" selected> - All - </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">
</div>

from this previous question:

Previous Question

I was wondering how can I populate the from a jQuery Array instead?

How could I do that? So basically the values and name from an array

This is the example in Fiddle i will be using Example Working

1

2 Answers 2

0
function populateSelect(el, items) {
    el.options.length = 0;
    if (items.length > 0)
        el.options[0] = new Option('please select', '');
    $.each(items, function () {
        el.options[el.options.length] = new Option(this.name, this.value);
    });
}

As seen here: Using javascript and jquery, to populate related select boxes with array structure

Sign up to request clarification or add additional context in comments.

Comments

0

You may want to retrieve names and values from JSON array this way.

var image_maps = {image1: "image1.jpg", image2: "image2.jpg"};
$.each(image_maps , function(name, value) {
    alert("name: " + name + " value: " + value);
});

1 Comment

Please accompany you code with explanatory comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.