0

I have a consent form section of a website, and I want to make it necessary to check the consent checkbox before moving on.

function consentCheck() {
  var tick = document.getElementById("checkbox2").checked

  if (tick == true) {
    window.location.href = "details.html";
  }
  else {
    window.alert("You must consent to move on.");
    window.location.href = "consentform.html";

  };
};

The problem that I'm getting is that whether the box is checked on not, it is returning to the consentform.html. I have tried logging the tick value and that is correct, but something about the if/else statement isn't working. Oddly, when I put a window.alert statement outside of the if/else statement it sent me to the correct address, and in fact when I put a window.alert statement instead of the href statement it logged that correctly as well.

Can someone explain why it's behaving so oddly?

Thanks!

Sam

0 Answers0