gafasmill gafasmill - 2 months ago 6x
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?


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.