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
<select name="country" id='country'>
<option value=""><?php echo '$text_select;' ?></option>
<?php while ($country=mysql_fetch_array($country_query)) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
Here you need to call ajax when country changed
JQuery :
<script src="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"