gafasmill gafasmill - 1 year ago 61
Javascript Question

Populating select shows 'undefined'

I am trying to populate a select from some data but it keep giving me undefined. The actual code works fine, I'm thinking its the format that's the problem?

Here's the code:

url: 'myurlhere',
method: 'GET',
async: false,
success: function(result) {
$.each(result, function(result, value) {

Here is the Data:

"type": "ford"
"type": "fiat"

How can I fix this?

Answer Source

You need to loop through, not result:

$.each(, function(i, value) {
    $('#myselect').append($('<option>', {

Working example

Also note that it's incredibly bad practice to useasync: false - if you check the browser you'll see warnings about its use. You should remove it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download