Checkbox to display a link

I want to have a simple checkbox at the end of some text that when clicked it will display a button. I added the following javascript to the Layout CSS and javascript tool.

function wdc_covid() {
  var checkBox = document.getElementById("myCheck");
  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";
  }
}

I then added the following to a text module on the page I wanted to display the button.

<input type="checkbox" id="myCheck" onclick="wdc_covid()">

It is simple and it works. However, if I open the text module to edit or to add something, the onclick="wdc_covid() disappears and it no longer calls the javascript function. Is there something that I can do so that I don’t have this problem?

Yes, use an HTML module instead :slight_smile: