Tony
Tony

Reputation: 12695

jQuery: A problem with .each function

I send to the javascript an array like:

enter image description here

 $.each(data, function (value, name) {
    $('#visitStart').append($('<option></option>').val(value).html(value));
 });

and as a result I see that the visitStart input is filled by values from 0 to 241. Why ?

Upvotes: 1

Views: 224

Answers (1)

Dogbert
Dogbert

Reputation: 222168

$.each sends an index, and value into the callback function - http://api.jquery.com/jQuery.each/

 $.each(data, function (i, obj) {
    $('#visitStart').append($('<option></option>').val(obj.value).html(obj.value));
 });

Upvotes: 6

Related Questions