0
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m1" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m2" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m3" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m4" />

How can I disable m1 and m3? I tried:

J("input:checkbox[name=chk_wms[value='m1']]").attr("disabled", true);   

And I would like to combine the command in one jQuery call something like:

J("input:checkbox[name=chk_wms[value='m1']], input:checkbox[name=chk_wms[value='m3']] ").attr("disabled", true);    
4
  • by the way if 1,3 is consistent you could use 'odd' selector that would do the trick Commented Nov 18, 2011 at 16:07
  • 1
    by the way this awfully complicated selector and overly specific on the left side that should be less specific., you don't really need the name selector etc.. Commented Nov 18, 2011 at 16:09
  • I find your question hard to understand in this format - could you edit refine your question or start a new one? Commented Nov 25, 2011 at 13:04
  • @alonisser I created another question: link Commented Nov 25, 2011 at 13:46

2 Answers 2

5

The problem is your attribute selector is incorrect. You've nested the attribute selector when really you need to make them siblings. Additionally you need to escape the [] in the name of the checkbox. Try the following

J('input:checkbox[name="chk_wms\[\]"][value="m1"]').attr('disabled', true);

Fiddle: http://jsfiddle.net/xMwMQ/

Sign up to request clarification or add additional context in comments.

2 Comments

by the way - if when you say disable you mean unchecked you should replace attr with .prop("checked",false)
great - than you should except this answer (by @JaredPar) -asking good questions and excepting good answers is what drives this community
1

use prop instead

J('input:checkbox[name="chk_wms"][value="m1"]').prop('disabled', true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.