This is pretty straight-forward and is usually easier than most people think. What I would do is call a function in the onchange attribute. In the following example the onchange attribute will be watching a dropdown, so the function will be called upon when the value of the dropdown changes:
<select onchange="myFunction()">
Then in my script I could have a javascript function with a jQuery AJAX block:
function myFunction(){
$.ajax({url:"script.php", success:function(result){
something here to output the result, like a div update.
}});
}
Then in script.php
validate and execute your SQL query. The need to call upon another script arises from Javascripts inability to communicate with the server, unless you're using node.js, which is a totally different kettle of fish. Javascript is a client side language and everything it does is completed in the users browser. By using jQuery's Ajax we can call upon a server side script from the users browser when a change is made.
I hope this makes sense, but I didn't have much from you to work with.
See more: http://api.jquery.com/jquery.ajax/
Regards,
M