lundi 27 juillet 2020

How to prevent a function from running until the user has given input?

I am creating a quiz and I don't want the next question to appear until the user has selected an answer to the first question, by ticking one of the checkboxes. If they haven't yet selected an answer, and try to click the NEXT buttton, an alert should pop up. How would I do this using javascript? My HTML:

<div id= "Q1"> Select your answer:
<input type = "checkbox" class="a"> a <br>
<input type="checkbox" class="b"> b <br>
</div>
 <button id="nextbtn" onclick="nextClicked()">NEXT</button>
<div id= "Q2"> Select your answer:
<input type = "checkbox" class="a"> a <br>
<input type="checkbox" class="b"> b <br>
</div>

My JS:

function nextClicked() {
                var Q2 = document.getElementById("Q2")
                Q2.style.opacity = "1"

                ``



Aucun commentaire:

Enregistrer un commentaire