Skip to content Skip to sidebar Skip to footer

Javascript Select City From Selected Country Value

i have db of countries from here http://www.webmasterworld.com/html/3018309.htm with 239 countries, every country have value. After i have selected another country in option, how c

Solution 1:

First time by default counties list will be loaded.. to load zones use this

<selectname="country"id='country'><optionvalue=""><?phpecho'$text_select;'?></option><?phpwhile ($country=mysql_fetch_array($country_query)) { ?><?phpif ($country['country_id'] == $country_id) { ?><optionvalue="<?phpecho$country['country_id']; ?>"selected="selected"><?phpecho$country['name']; ?></option><?php } else { ?><optionvalue="<?phpecho$country['country_id']; ?>"><?phpecho$country['name']; ?></option><?php } ?><?php } ?></select>

Here you need to call ajax when country changed

JQuery :

<scriptsrc="http://code.jquery.com/jquery-latest.js"></script><script>
$(document).ready(function(){

    $('#country').change(function(){

        $.post('ajax/getZones', 
                   {Country : $('#country').val()}, 
                   function(response){
                     //prepare the zones html code//write that code to zone dropdown 
                  }, 'json');

    });

});
</script>

Here 'ajax/getZones' refers getZones is the method in ajax controller

write the getZones query in getZones(ajax) get the Country id with $_POST['Country'] in ajax controller

try implement ajax controller everything work fine..

Post a Comment for "Javascript Select City From Selected Country Value"