dimanche 10 novembre 2019

Display Link only when multiple checkboxes are clicked

I've tried making a link appear only when multiple checkboxes are clicked. It's for a testing website i'm building for my job and I can't get it right. Basically when I ask a question, multiple answers are necessary for the answer to be correct, so I want to put in a system so that only when all these answers are clicked will the link to the next question shows up. I'll need to know what to put into each checkboxs code so I know how to put wrong answers into the site

I've tried a code I found on here, that was meant for one checkbox and tried various methods for multiplying the checkbox but I am unable to get it to only show when all checkboxes are checked.

function toggleLink1(checkBox) {
  var link = document.getElementById("agreeLink");
  if (checkBox.checked)
    link.style.display = "inline";
  else
    link.style.display = "none";
}
<form>
  <p><input type="checkbox" id="agreeCheckbox" name="agreeCheckbox" value="agreeCheckbox" onchange="toggleLink(this);">By clicking this you agree that you are adding a subscription/recurring product to your order</p>
</form>

These were the base lines of code I tried modifying to suit my purposes, but it failed

I expected the link to appear only when all checkboxes are used, but it appears after only one is clicked, then if I click the other box used for testing, and uncheck either one, the link disappears again.




Aucun commentaire:

Enregistrer un commentaire