Input Checkbox checked Property - Find out if a checkbox is checked or not: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Checkbox

Description

Input Checkbox checked Property - Find out if a checkbox is checked or not:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Checkbox: <input type="checkbox" id="myCheck">

<button onclick="check()">Check Checkbox</button>
<button onclick="uncheck()">Uncheck Checkbox</button>

<script>
function check() {//  ww w .ja va 2 s.  c  o m
    document.getElementById("myCheck").checked = true;
    var v = document.getElementById("myCheck").checked;
    console.log(v);
}

function uncheck() {
    document.getElementById("myCheck").checked = false;
    var v = document.getElementById("myCheck").checked;
    console.log(v);

}
</script>

</body>
</html>

Related Tutorials