I’m beginner and have trouble with something in JS that might be simple to solve.
I made a quiz based on a NetNinja Udemy course, and I want the submit button to be enabled just when the user clicks on any answer option, and not before, so that he/she can’t send a totally empty quiz.
The quiz has 4 questions with 2 options each, and I found this way…
const input_a = document.getElementById("q1a");
const input_b = document.getElementById("q1b");
button.disabled = true;
input_a.addEventListener('click', () => {
button.disabled = false;
});
input_b.addEventListener('click', () => {
button.disabled = false;
});
…to enable the button when the user clicks on any of the two options of the first question (ids: q1a & q1b) Following this logic, there’d also be q2a, q2b, q3a, q3b, q4a & q4b..
As there is a way to include all the answers in one JS element, what should I do in the event function to say “when you click any of this 8 options, enable the button”? Because everything I tried only makes the function work if I click all the buttons, which is obviously impossible in a Quiz .
Thank you! 🙂