I have an html that can contain multiple input[submit] dynamically loaded from multiple php files via includes. The thing is that I try to ensure that all the buttons, by default, remain with the disabled property from the beginning of the html and until the user does certain operations they are not enabled.
At the moment I have managed to disable all or none of them, but I can't get them to deactivate all except one of them, with a specific ID, which belongs to the menu where the user can do a search.
var $selects = $('select');
var $buttons = $('input[type="submit"]');
function checkSelect() {
for ( var n = 0; n < $selects.length; n++ ) {
//if value of any of the selects is empty disable buttons and return false
if ( $($selects[n]).val() == 'nulo' ) {
disableButtons();
return false;
}
}
enableButtons();
return true;
}
function disableButtons() {
for ( var n = 0; n < $buttons.length; n++ ) {
if ($($buttons[n]).attr('id') != 'btnSearchFilter') {
$buttons[n].attr('disabled', 'disabled');
}
}
}
function enableButtons() {
$buttons.removeAttr('disabled');
}
$selects.on('change', checkSelect());
$(document).ready(checkSelect());
It is in the line of if ($($buttons[n]).attr('id') != 'btnSearchFilter') { where I imagine that filter should be put, but as I have it, it gives me an error indicating that $ buttons[n].attr is not a function
jQuery has the expression
:not()
. I enclose a small demonstration of its use: