mercredi 6 janvier 2016

How to disable controls when checkbox is deselected or not selected at all in jquery?

I have the following html

<form>
  <p>
    <input type="checkbox" name="[1]option" value="Hourly" >
    <input type="checkbox" name="[2]option" value="Daily">
    <input type="checkbox" name="[3]option" value="Weekly">
    <input type="checkbox" name="[4]option" value="Monthly">
    <input type="checkbox" name="[5]option" value="Yearly">
  </p>

   <p>
    <input type="checkbox" name="cheque" value="cheque" disabled>
    <input type="checkbox" name="Online" value="Online" disabled>
    <input type="text" name="Accountnumber" id="generate" disabled>
  </p>
</form>

I tried this

<script type="text/javascript">
     $("input:checkbox").on('click', function () {
         $('#generate').prop('disabled', false);
         $("input").prop('disabled', false);
     });
</script>

It works. But if I deselect all checkbox, the controls are not getting disabled. My requirement is if only any check box is selected the controls should get enabled. Any help much appreciated.




Aucun commentaire:

Enregistrer un commentaire