admin管理员组文章数量:1023251
I'm using this Country / State dynamic selection on my code :
/
and here's the demo page : /
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!
I'm using this Country / State dynamic selection on my code :
http://bdhacker.wordpress./2009/11/21/adding-dropdown-country-state-list-dynamically-into-your-html-form-by-javascript/
and here's the demo page : http://bdhacker.sourceforge/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!
Share Improve this question asked Nov 15, 2012 at 14:25 Saint RobsonSaint Robson 5,52518 gold badges74 silver badges121 bronze badges 2-
Have you included the function and data in your page?
<script type="text/javascript" src ="countries-2.0-min.js"></script>
(you'll obviously need to update the path to the file) – peterph Commented Nov 15, 2012 at 14:37 - I have. I can see my dropdown menu works exactly like demo page. but when I add : <select onChange="print_state(\'state\',this.selectedIndex);" id="country" name = "country"><option value="Indonesia" selected>Indonesia</option></select> I still can't see a country selected. – Saint Robson Commented Nov 15, 2012 at 14:44
2 Answers
Reset to default 1try this solution http://jsfiddle/yDAmR/
print_country("country");
$('#country').val('Indonesia');
print_state('state',$('#country')[0].selectedIndex);
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.
I'm using this Country / State dynamic selection on my code :
/
and here's the demo page : /
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!
I'm using this Country / State dynamic selection on my code :
http://bdhacker.wordpress./2009/11/21/adding-dropdown-country-state-list-dynamically-into-your-html-form-by-javascript/
and here's the demo page : http://bdhacker.sourceforge/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!
Share Improve this question asked Nov 15, 2012 at 14:25 Saint RobsonSaint Robson 5,52518 gold badges74 silver badges121 bronze badges 2-
Have you included the function and data in your page?
<script type="text/javascript" src ="countries-2.0-min.js"></script>
(you'll obviously need to update the path to the file) – peterph Commented Nov 15, 2012 at 14:37 - I have. I can see my dropdown menu works exactly like demo page. but when I add : <select onChange="print_state(\'state\',this.selectedIndex);" id="country" name = "country"><option value="Indonesia" selected>Indonesia</option></select> I still can't see a country selected. – Saint Robson Commented Nov 15, 2012 at 14:44
2 Answers
Reset to default 1try this solution http://jsfiddle/yDAmR/
print_country("country");
$('#country').val('Indonesia');
print_state('state',$('#country')[0].selectedIndex);
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.
本文标签: phpSelected CountryState From Dynamic Dropdown ListStack Overflow
版权声明:本文标题:php - Selected CountryState From Dynamic Dropdown List - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745522908a2154397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论