Reputation: 5525
I'm using this Country / State dynamic selection on my code :
and here's the demo page : http://bdhacker.sourceforge.net/javascript/countries/
but, unfortunately when I create setting / member profile page which I need to display selected country and state so user can see what they already chosen, I can't just put user's selected as 'value' on it.
here's what I see on page source even I have select a country and a state :
Select Country: <select onchange="print_state('state',this.selectedIndex);" id="country" name ="country"></select>
City/District/State: <select name ="state" id ="state"></select>
how to put value on that ? because I did like this :
Select Country:
<select onchange="print_state('state',this.selectedIndex);" id="country" name ="country" value="Indonesia"></select>
City/District/State: <select name ="state" id ="state"></select>
and still I don't see there's a country selected. thanks!
Upvotes: 0
Views: 13553
Reputation: 1
The reason you see the USA states for other countries is that the JavaScript is missing a reset of the state drop-down list. Just add "option_str.length=0; // Clear list" in the JS file before you split list array.
Upvotes: 0
Reputation: 1658
try this solution http://jsfiddle.net/yDAmR/
print_country("country");
$('#country').val('Indonesia');
print_state('state',$('#country')[0].selectedIndex);
Upvotes: 1