You can do it with jQuery and AJAX
jQuery.post('dropdownValues.php', {parameterSentToServer1:'value', param2:'value2'}, function(data){jQuery('#mydropdown option').remove();
for (var option in data.results){
jQuery('#mydropdown').append('<option value="'+option.value+'">'+option.name+'</option>');
}}, 'json');
in dropdownValues.php you will need to build a json object with the result of the SQL query, the object must be in this format (for good work with the above script):
echo '{results:[{value:1, name:'Option1'}, {value:2, name:'Option2'}]};
source
share