Submit form on select change via AJAX
Getting cross browser onchange
events and AJAX requests working isn't trivial. I'm recommend you use a javascript framework of some kind, which abstracts away all of the cross browser issues so you don't have to worry about them.
Try a js framework
Jquery is just one such framework which has methods such as .change()
which attaches a handler to the change event for elements like <select>
and .get()
which performs a GET request.
Here's a little bit of code to get you started:-
// The $ is the shorthand for a jquery function, you can then use jquery // selectors which are essentially the same as css selectors, so here// we select your select field and then bind a function to // it's change event handler$('select.changeStatus').change(function(){ // You can access the value of your select field using the .val() method alert('Select field value has changed to' + $('select.changeStatus').val()); // You can perform an ajax request using the .ajax() method $.ajax({ type: 'GET', url: 'changeStatus.php', // This is the url that will be requested // This is an object of values that will be passed as GET variables and // available inside changeStatus.php as $_GET['selectFieldValue'] etc... data: {selectFieldValue: $('select.changeStatus').val()}, // This is what to do once a successful request has been completed - if // you want to do nothing then simply don't include it. But I suggest you // add something so that your use knows the db has been updated success: function(html){ Do something with the response }, dataType: 'html' });});
Some references that will be better than my explanations
Please note for this code to work you will need to include the jquery library on you page with a <script>
tag.
See here for a quick start guide on using jquery
And here for a beginners tutorial on how to use jquery's ajax()
method