2
Good morning.
I am doubtful to do a validation in two selects in jquery.
I need the button to only enable when the two selects are with some selected value.
But the way I did, it validates if the first select is not empty, and the second and if I do otherwise, select the second select first, it does not understand.
I did the function completely wrong. I did the validation with the first select and then with the second, using if. Some can help me?
as is.
$("#select-1").change(function(){
if( $('#select-1').val() != 0 ){
$("#select-2").change(function(){
if( $('#select-2').val() != 0 ){
botaoBuy.attr("disabled", false);
botaoBuy.css("opacity","1");
}else{
botaoBuy.attr("disabled", true);
botaoBuy.css("opacity","0.4");
}
});
}else{
botaoBuy.attr("disabled", true);
botaoBuy.css("opacity","0.4");
}
});
Concise and correct answer, not to mention that it caches the DOM elements so as not to waste computational resources. + 1
– fernandosavio