jeudi 23 mai 2019

Checkbox checked works only once

Message sending form, the customer has to select at least one of the alternatives (mail, SMS).

Send button would be disabled if none is selected and activate if one or both selected

$(document).ready(function() {
  $('.form-check-input').change(function() {
    $(this).each(function() {
      if (!$(this).is(':checked')) {
        $("#send").attr("disabled", "disabled");
      }
    });
  });
});
<div>
  <div class="row">
    <div class="col-md-12 form-check">
      <div>
        <input class="form-check-input" type="checkbox" value="" id="Epost" checked>
        <label class="form-check-label" for="E-post">E-post</label>
      </div>
      <div>
        <input class="form-check-input" type="checkbox" value="" id="SMS">
        <label class="form-check-label" for="SMS">SMS</label>
      </div>
      <br>
      <button id='send'>Send</button>
    </div>
  </div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



Aucun commentaire:

Enregistrer un commentaire