How to display text when the checkbox is selected
- Previous Page Toggle Switch
- Next Page Detect Capital Lock
Use JavaScript to check if the checkbox is selected.
Display some text when the checkbox is selected:
Checkbox:
Check if the checkbox is selected
Step 1 - Add HTML:
Checkbox: <input type="checkbox" id="myCheck" onclick="myFunction()"> <p id="text" style="display:none">Checkbox is CHECKED!</p>
Step 2 - Add JavaScript:
function myFunction() { // Get the checkbox var checkBox = document.getElementById("myCheck"); // Get the output text var text = document.getElementById("text"); // If the checkbox is selected, then display the output text if (checkBox.checked == true){ text.style.display = "block"; } text.style.display = "none"; } }
- Previous Page Toggle Switch
- Next Page Detect Capital Lock