How can I check if a checkbox is checked?

Solution 1:

checked is a boolean property, so you can directly use it in an if condition

<script type="text/javascript">
    function validate() {
        if (document.getElementById('remember').checked) {
            alert("checked");
        } else {
            alert("You didn't check it! Let me check it for you.");
        }
    }
</script>

Solution 2:

Try this:

function validate() {
  var remember = document.getElementById("remember");
  if (remember.checked) {
    alert("checked");
  } else {
    alert("You didn't check it! Let me check it for you.");
  }
}

Your script doesn't know what the variable remember is. You need to get the element first using getElementById().

Solution 3:

This should allow you to check if element with id='remember' is 'checked'

if (document.getElementById('remember').is(':checked')