Javascript DOM HTML Input Checkbox Object get

Introduction

The Input Checkbox object represents an HTML <input> element with type="checkbox".

We can access an <input> element with type="checkbox" via document.getElementById():

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

Click the "Test" button to check the checkbox.

View in separate window

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

<script>
function myFunction() {//from   w w  w.  j a  va2  s  .  c o m
  var x = document.getElementById("myCheck");
  x.checked = true;
}
</script>

</body>
</html>



PreviousNext

Related