Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  126] [ 5]  / answers: 1 / hits: 27613  / 11 Years ago, wed, april 3, 2013, 12:00:00

jsFiddle



I have got a simple select menu containing all countries with their city's listed in respective option value.
The value also contains some other data, for instance Canada has value +1|}|22|X while United States has this +1|}|128|X||{|58$Abilene#|{|59$Akron#|{|1$Alabama#|{|2$Alaska#|{|60$Albany#|....



I need to fill another select menu on change of country select menu.
I can't figure out how can i parse each city listed in the country's value.


More From » jquery

 Answers
20

Maybe try this, idk, that data was kind of weird:



$('#country_residence').on('change', function () {
var cities = $(this).val().split('$');
$(#cities option).remove();
for(var i = 1;i<cities.length;i++)
{
var city = String(cities[i]);
if(city.indexOf(#)>-1)
city = city.substring(0,city.indexOf(#));


$(#cities).append(<option> + city + </option>);
}
});


jsFiddle: http://jsfiddle.net/EyVuS/3/


[#79135] Tuesday, April 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diontajm

Total Points: 391
Total Questions: 104
Total Answers: 104

Location: Netherlands
Member since Mon, Jun 7, 2021
3 Years ago
;