Javascript DOM HTML Input Checkbox checked Property get

Introduction

Find out if a checkbox is checked or not:

var x = document.getElementById("myCheck").checked;

Click button to find out whether the checkbox is checked, or not.

View in separate window

<!DOCTYPE html>
<html>
<body>

Checkbox: <input type="checkbox" id="myCheck">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/* w w  w  .ja  v  a  2 s.  c  om*/
  var x = document.getElementById("myCheck").checked;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related