Wednesday, March 1, 2017

How to disable all non selected values in all select boxes with jQuery?

I have a model in Laravel that can be edited with dynamic form but i want to prevent changing the selected option in select box so when i open the edit page i should be able to see the select boxes with selected items but all other options should be disabled.

Maybe i could just select all select with jQuery and disable all non selected values?? How to do that?

I have tried this:

// disable non selected items
$('select').each(function(){
    $('option').each(function() {
        if(this.selected) {
            this.attr('disabled', true);
        }
    });
});

But it doesn't work, i just need a little help




via lewis4u

Advertisement