jeudi 18 juillet 2019

If Checkbox is Checked Keep DIV hidden even on page reload

I have a rails form. When a checkbox is selected (true in database) I want to keep the div hidden. I found other solutions but on page reload it reappears, I'd like to keep the div hidden if checked or true.

  <div class="form-group">
    <%= form.check_box :tos_checkbox, class: "terms_of_services" %>
    <%= form.label :tos_checkbox, "Agree to TOS" %>
  </div>

  <div id="hide_if_above_checked">
    Do You Agree to Our TOS
  </div>

I know this script will not work, but been attempting several different examples to solve my problem.

  $(function () {
      $('.terms_of_services').change(function () {
          if(checkbox.checked == true){
              document.getElementById("hide_if_above_checked").setAttribute("d-none");
          }else{
              document.getElementById("hide_if_above_checked").removeAttribute("d-none");
          }
      });
  });




Aucun commentaire:

Enregistrer un commentaire