Change Dropbox background to reset

I have a group of drop-down boxes that, since the value is used in 1 field, it is disabled, and the background of the value changes to gray in others. It works great. My problem is that when I reset the form, the backgrounds do not return to white, and the values ​​remain disabled. I use the usual input type = 'reset "to clear the form. This is the function I use to change the background.

function CheckSelected() {
    $(document).on('change', 'select', function () {
        $('option[value="disabled"]').prop('disabled', false);
        $(this).addClass('exception');
        $('option[value="' + this.value + '"]:not(.exception *)').prop('disabled', true);
        $('option[value="' + this.value + '"]:not(.exception *)').css('background-color', 'grey');
        $(this).removeClass('exception');
    });
}
+4
source share
1 answer

You can listen to the form reset and reset the background color:

$(document).on('reset', 'form', function() {
    $(this).find('option').css('background-color', '');
});

http://jsfiddle.net/262ro32y/1/

You can also remove the style attribute instead of setting the background color to an empty string:

$(this).find('option').removeAttr('style');
0
source

All Articles