I have a php function that list all of the countries from my database as a select option, then based on what the user selects for their country im using jquery to make an ajax call and get all of the states/regions for that country. This part works fine. I'm running into an issues, as when a user login's in to edit their profile, how would I make the select change based on what is in the databse.
This makes the options.
<select name='country' id='country'>
<? getCountry($c['country']); ?>
</select>
Then this is the jquery
$("#country").change(function() {
var ctry = $(this).val();
$.get("core/ajax/states.php", {
country: ctry
}, function(data) {
var opt = '';
if (!data) {} else {
$.each(data, function(n, val) {
if(!n){} else{
opt += '<option value="' + val.code + '">' + val.name + '</option>';
}
});
$("#state").html(opt);
}
}, 'json');
});
$("#country").change();
Any help on this matter would be great.
Thanks for your time
-BaSk