I am trying to iterate thru arrays to get country info for a dropdown.
These are the arrays:
var array_states_US = new Array("AL", "AK", "AR")
var array_states_names_US = new Array("Alabama", "Alaska", "Arkansas")
var array_states_MX = new Array("AG", "BN", "BS")
var array_states_names_MX = new Array("Aguascalientes", "Baja California", "Baja California Sur")
Here is the function:
function buildDropdown(countryISO){
var tmpArry = 'array_states_' + countryISO;
var tmpArryNames = 'array_states_names_' + countryISO;
$(tmpArry).each(function(i) {
$(stateSelectId).append($("<option></option>").attr("value", this).text($(tmpArryNames)[i]));
});
}
But JQuery sees $(tmpArry) and $(tmpArryNames) as strings instead of the array values. (When I used MooTools in a past project for this, the dynamic var was not a problem.) If i use $(array_states_MX) and $(array_states_names_MX) instead, then it works. But the countryISO value has to be dynamic.
What is the correct syntax to make this work?