How to find all the selected items that have changed?

advertisements

let's say I have a form that contains several "select" element that the User can choose. when ready to submit, I need to find all the "select" that have changed. how can I do it?

for example:

<form>
    <input type="text" name="a"/>
    <select name="b">...</select>
    <select name="c">...</select>
    <select name="d">...</select>
</form>

Using jQuery, something like this should work:

$('select').change(function() {
    $(this).addClass('changed');
});

$('form').submit(function() {
    var changed_selects = $('select.changed');
    // do what you want with the changed selects
});