Here's my js code:
// at first the three buttons have value 1
var clicks = [1,1,1];
// if (at least one button has value 2) {"button-next" = enabled}
if (clicks.some(x => x == 1)) {
document.getElementById("button-next").disabled = true;
} else {
document.getElementById("button-next").disabled = false;
}
If at least one of the three values is 2, button-next must be enabled.
With jQuery I managed to change the variabales to 2 at the first click (and the opacity to 1) and back to 1 at the second click (and the opacity back to 0.5):
$(document).ready(function(){
// BUTTON 1
$("#button1").click(function(){
if (clicks[0] == 1) {
jQuery("#button1").css('opacity', '1');
clicks[0] = 2;
} else {
jQuery("#button1").css('opacity', '0.5');
clicks[0] = 1;
}
});
// BUTTON 2
$("#button2").click(function(){
if (clicks[1] == 1) {
jQuery("#button2").css('opacity', '1');
clicks[1] = 2;
} else {
jQuery("#button2").css('opacity', '0.5');
clicks[1] = 1;
}
});
// BUTTON 3
$("#button3").click(function(){
if (clicks[2] == 1) {
jQuery("#button3").css('opacity', '1');
clicks[2] = 2;
} else {
jQuery("#button3").css('opacity', '0.5');
clicks[2] = 1;
}
});
});
When I click on a button once the value changes, but the button-next remains disabled. It looks like the changes are not detected. I tried to change it manually like this:
var clicks = [1,2,1];
And I proved that these lines work:
if (clicks.some(x => x == 1)) {
document.getElementById("button-next").disabled = true;
} else {
document.getElementById("button-next").disabled = false;
}
Because at that point button-next was enabled back. I don't know how to fix it. Do you have any idea?