JavaScript Checkbox Checked or Not

In this tutorial we will see how to Check if Checkbox is Checked or Not in JavaScript. HTML DOM Input Checkbox checked Property can be used to check the state of a checkbox.

Checked Property

The HTML DOM Checked Property either checks or unchecks the checkbox or it is used to read the state of the checkbox.

In this example checked property is used to check if checkbox is checked or not.

HTML Code

HTML Code is given below, This code contains a label tag for the checkbox and a button tag with onclick event.

<label>Checkbox</label>
<input id='chk' type="checkbox">  
<br><br>
<button onclick="checkFunction()">Check If Checked or Not</button>

JavaScript Code

JavaScript Code is given below, this code will check the state of the checkbox. The code will be executed on click event of button tag.

getElementById() is used to select the checkbox using it's id. The checked property will either return true or it will return false depending on the state of checkbox.

True is returned if checkbox is checked, otherwise False is returned.

<script>
function checkFunction()
{
  var checkbox = document.getElementById("chk").checked;
  if(checkbox)
  {   
  alert('Checkbox is Checked!');
  }  
  else
  {   
  alert('Checkbox is not Checked!');
  }
}
</script>

Demo

Video Tutorial

Watch video tutorial on how to Check if Checkbox is Checked or Not using JavaScript.

Change font-size using JavaScript Get Font Size of any Tag using JavaScript Change Position of HTML Element using JavaScript How to Change Image on Hover with JavaScript How to Disable Button by Class Name in JavaScript How To Change Image Size with JavaScript How to change Image opacity with JavaScript How to Change image src on click with JavaScript How to get the lang attribute value in JavaScript How to Get attribute Value using JavaScript How To Check if Attribute Exists or not with JavaScript How To Count number of links on Page with JavaScript How To Scroll Page to Bottom using JavaScript How To Detect Shift Key Press with JavaScript Change Text Color On Hover with JavaScript Hide and Show div using JavaScript Get Button text with JavaScript Get textarea value with JavaScript Get table row Height with JavaScript Auto Increase width of input field with JavaScript Set Textarea maxLength with JavaScript Set Textarea Value with JavaScript JavaScript Count list items JavaScript set input field value Count Button Clicks with JavaScript Scroll Page to the Top on Click with JavaScript