I\'m trying to write a php script that will populate a second drop down menu based on the selection of the a primary drop down menu. I would like to use jquery to do all the
Here's some code that should give you an idea of what you want to do:
HTML
PHP
array( 'Chicago', 'Naperville', 'Decatur', 'Saint Charles' ),
'IN' => array( 'Gary', 'Miller', 'Portage', 'Merrillville' )
);
print json_encode( $cities[ $_POST[ 'state' ] ] );
exit;
?>
jQuery
jQuery(document).ready(function() {
jQuery('#state').change(function() {
jQuery.post(
'some-url.php',
{
'state':jQuery('#state').val()
},
function(data, textStatus) {
jQuery.each(data, function(index, value) {
jQuery('#city').append('');
});
},
'json'
);
});
});