...
| Excerpt |
|---|
Checkbox object in HTML has a property checked as boolean - it has true or false, so javascript can check its status easily. |
| Code Block | ||
|---|---|---|
| ||
<script>
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("myCheck");
// Get the output text
var text = document.getElementById("text");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}
</script>
Checkbox: <input type="checkbox" id="myCheck" onclick="myFunction()">
<p id="text" style="display:none">Checkbox is CHECKED!</p> |
...