How to display text when the checkbox is selected

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";
  }
}

Try It Yourself