jeudi 30 janvier 2020

textbox not hiding with checkbox click (javascript)

I have a textbox which I would like to appear on a checkbox click and disappear if the checkbox is unselected, however my code currently shows the textbox when the page loads, but once you select and then unselect the checkbox it disappears as its supposed to. Any ideas?

Javascript:

function TMDFunction() {
  // Get the checkbox
  var checkBox = document.getElementById("tmd_checkbox");
  // Get the output text
  var text = document.getElementById("test");

  // If the checkbox is checked, display the output text
  if (checkBox.checked == true) {
    text.style.display = 'block';
  } else {
    text.style.display = 'none';
  }
}
<input type="checkbox" class="product" name="targetedmobiledisplay" value="0.08" id="tmd_checkbox" onclick="TMDFunction()">
Targeted Mobile Display
<br> 
Test: <input id="test" type="text" value="0.00" data-total="0" />



Aucun commentaire:

Enregistrer un commentaire