views:

73

answers:

2

How do I create an array of values from a drop down list?

+2  A: 

The following should do it. It will create an array from all the values of your select:

var data = $("#theSelect options").map(function() {
    return this.value;
}).get();
$('#txtEntry').autocomplete(data);
karim79
sorry--that's a no-go. I do get a VS message saying, 'get' is a new reserved word and should not be used as an identifier. Not sure if that's to blame or not.
Matt
+1 for mentioning .map()
takpar
A: 

This works instead:

var data[]; $('#ddlCodes option').map(function(i, option) { data[i] = $(option).val(); });

Matt