简体   繁体   中英

How to get the CITY value from javascript file using GET or POST in HTML form [CODE ATTACHED]?

How to retrieve the CITY value using GET or POST just like STATE value can be used using $_POST['stt']?

ps: New to stack overflow, so please suggest ways to ask questions in a better way:)

 var state_arr = new Array("Andaman & Nicobar"); var s_a = new Array(); s_a[0] = ""; s_a[1] = " Alipur | Andaman Island | Anderson Island | Arainj-Laka-Punga | Austinabad | Bamboo Flat | Barren Island "; function print_state(state_id) { // given the id of the <select> tag as function argument, it inserts <option> tags var option_str = document.getElementById(state_id); option_str.length = 0; option_str.options[0] = new Option('Select State', ''); option_str.selectedIndex = 0; for (var i = 0; i < state_arr.length; i++) { option_str.options[option_str.length] = new Option(state_arr[i], state_arr[i]); } } function print_city(city_id, city_index) { var option_str = document.getElementById(city_id); option_str.length = 0; // Fixed by Julian Woods option_str.options[0] = new Option('Select City', ''); option_str.selectedIndex = 0; var city_arr = s_a[city_index].split("|"); for (var i = 0; i < city_arr.length; i++) { option_str.options[option_str.length] = new Option(city_arr[i], city_arr[i]); } } print_state("sts");
 <form> <select onchange="print_city('state', this.selectedIndex);" id="sts" name="stt" class="form-control" required></select> <select id="state" class="form-control" required></select> </form>

Use this you will get both city and state give your filename in form action atribute

 var state_arr = new Array("Andaman & Nicobar"); var s_a = new Array(); s_a[0] = ""; s_a[1] = " Alipur | Andaman Island | Anderson Island | Arainj-Laka-Punga | Austinabad | Bamboo Flat | Barren Island "; function print_state(state_id) { // given the id of the <select> tag as function argument, it inserts <option> tags var option_str = document.getElementById(state_id); option_str.length = 0; option_str.options[0] = new Option('Select State', ''); option_str.selectedIndex = 0; for (var i = 0; i < state_arr.length; i++) { option_str.options[option_str.length] = new Option(state_arr[i], state_arr[i]); } } function print_city(city_id, city_index) { var option_str = document.getElementById(city_id); option_str.length = 0; // Fixed by Julian Woods option_str.options[0] = new Option('Select City', ''); option_str.selectedIndex = 0; var city_arr = s_a[city_index].split("|"); for (var i = 0; i < city_arr.length; i++) { option_str.options[option_str.length] = new Option(city_arr[i], city_arr[i]); } } print_state("sts");
 <form method="get" action="filename.html"> <select onchange="print_city('state', this.selectedIndex);" id="sts" name="state" class="form-control" required></select> <select id="state" name="city" class="form-control" required></select> <input type="submit" value="submit"/> </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM