mardi 21 février 2017

checkbox change not fired at page load time

I have a button and checkbox(terms of use) in my page.
The button should be disabled if the checkbox is not checked.

I want to reset the situation in every load. (first load or using back btn or etc) the reset state is: checkbox shouldn't be checked, and btn is disabled. But the function is called just when I click the checkbox, and not at load time. Update: Also I tested .trigger('change'), too. It did't work too

$(function() {
  $('#termsOfUse').removeAttr('checked');
  $('#termsOfUse').change();
  $('#termsOfUse').change(function() {
    if ($(this).is(":checked")) {
      $('#createBtn').prop('disabled', false);
    } else {
      $('#createBtn').prop('disabled', true);
    }
  });
});
<script src="http://ift.tt/1oMJErh"></script>
<div class="row">
  <input id="termsOfUse" type="checkbox" />
  <label for="termsOfUse" style="display: inline;">
                   <span><a href="/rules">rules</a></span> I am agree with</label>
</div>
<div class="create">
  <input id="createBtn" type="button" value="create" class="btn btn-default btn-success" 
  onclick="location.href = '@Url.Action("Create","NewOne ")'" />
</div>



Aucun commentaire:

Enregistrer un commentaire