javascript - Checkbox doesn't want to toggle enable disable field -


i have check box , field. default field needs disabled. check box checked, field should enable.

i've tried literally every answer here no luck. i've tried css failed there too. when try of samples in fiddle or ever else work, in project don't.

what have simple test when click #clicker, field disables/enables. works perfectly. know javascript work, don't require libraries whatsoever. need adjust code work when check box checked or not.

this have;

<script type="text/javascript"> $().ready(function() {     $('#clicker').click(function() {         $('#form_secondapprover').each(function() {             if ($(this).attr('disabled')) {                 $(this).removeattr('disabled');             }             else {                 $(this).attr({                     'disabled': 'disabled'                 });             }         });     }); }); 

here pure javascript solution answer !!

document.addeventlistener("domcontentloaded", function(event) {      var checkbox = document.getelementbyid('clicker');      var inputs = document.queryselectorall('input[type=text]');      checkbox.addeventlistener('change', function(event) {          (var = 0; < inputs.length; i++) {              inputs[i].disabled = !checkbox.checked;          }      });  });
input[type="text"]:disabled {    cursor: not-allowed;  }
<input type="checkbox" id="clicker" />  <label for="clicker">click me, i'll disable/enable these text boxes</label>    <form id="form_secondapprover">    <input type="text" disabled/>    <input type="text" disabled/>    <input type="text" disabled/>  </form>

here fiddle if want play :)


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -