Home > OS >  Display button if checkbox is checked
Display button if checkbox is checked

Time:09-07

I would like to show a button when a checkbox is checked.

Unfortunately I couldn't find a solution on the internet... Does somebody know how to solve my problem?

Currently this is where I stand:

<div >
    <input th:id="checkboxTerms" th:checked="${flag}" type="checkbox" >
    <label >Terms & Conditions</label>
</div>

<div th:if="${flag == true}">
    <!-- Create Account Button -->
    <button  type="submit" id="idBtnSub">Create Account</button>
</div>

CodePudding user response:

<script>
  function toggleButton() {
    if (document.getElementById("idBtnSub").style.visibility == "hidden") {
      document.getElementById("idBtnSub").style.visibility = "visible";
    } else {
      document.getElementById("idBtnSub").style.visibility = "hidden";
    }
  }
</script>



<div >
  <input onChange="toggleButton();" "th:id="checkboxTerms" th:checked="${flag}"
  type="checkbox" >
  <label >Terms & Conditions</label>
</div>

<div th:if="${flag == true}">
  <!-- Create Account Button -->
  <button
    
    type="submit"
    id="idBtnSub"
    style="visibility: hidden;"
  >
    Create Account
  </button>
</div>

  • Related