javascript checkbox value if checked code example

Example 1: get the state of a checkbox

function checkAddress()
{
    var chkBox = document.getElementById('checkAddress');
    if (chkBox.checked)
    {
        // ..
    }
}

Example 2: how to check if input is checked javascript

const cb = document.getElementById('accept');
console.log(cb.checked);

Example 3: check if checkbox is checked javascript

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

<input id="remember" name="remember" type="checkbox" onclick="validate()" />

Tags:

Html Example