javascript - How to disable checkbox with jquery? -


i searched more time it's not work, want checkbox disabled, user not check , can check if condition. ok, now, tried disabled them. use jquery 2.1.3

 <input type="checkbox" class="checkbox1" id="chk" name="check[]" value="u01" />banana   <input type="checkbox" class="checkbox1" id="chk" name="check[]" value="u02" />orange   <input type="checkbox" class="checkbox1" id="chk" name="check[]" value="u03" />apple   <input type="checkbox" class="checkbox1" id="chk" name="check[]" value="u04" />candy

$(window).load(function () {     $('#chk').prop('disabled', true); }); 

id should unique. cannot have 4 checkboxes same id.

you can try other selectors select whole range of checkboxes, .checkbox1 (by class), input[type="checkbox"] (by tag/attribute). once you've fixed ids, try #chk1, #chk2, #chk3, #chk4.

the snippet below uses classname 'chk' instead of id 'chk'. also, uses attr set attribute although did work me using prop well.

$(window).load(function() {    $('.chk').attr('disabled', true);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="checkbox" class="chk" name="check[]" value="u01" />banana  <input type="checkbox" class="chk" name="check[]" value="u02" />orange  <input type="checkbox" class="chk" name="check[]" value="u03" />apple  <input type="checkbox" class="chk" name="check[]" value="u04" />candy


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -