0

I have a check box list which enables multi select. i need to get the label of each check box instead of the value and do some work. if values are aaa &&& bbb i need to disable them (not allow user to check) and others i want to display as check able.

I have this piece of code written but doesn't work. I think I am missing something.

  $('#ddcl-ddlOutcomeList-ddw input[type=checkbox]').each(function () {
      console.log($(this).html());
   });

ex:

  <div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
  <input type="checkbox" tabindex="0" class="active" id="ddcl-ddlOutcomeList-i0" index="0" value="1444">
  <label for="ddcl-ddlOutcomeList-i0" class="ui-dropdownchecklist-text" style="cursor: default;">No answer</label>
  </div>

 <div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
 <input type="checkbox" tabindex="1" class="active" id="ddcl-ddlOutcomeList-i1" index="0" value="1445">
 <label for="ddcl-ddlOutcomeList-i1" class="ui-dropdownchecklist-text" style="cursor: default;">No answer 2</label>
 </div>
5
  • can you post your html here or create a fiddle? Commented Jul 4, 2013 at 10:09
  • @dfsq please check the below answer. i was able to get my work done with it. Commented Jul 4, 2013 at 10:20
  • dfsq answer is working... check it... Commented Jul 4, 2013 at 10:24
  • no it doesnt work for me. please help me with my below question Commented Jul 4, 2013 at 11:06
  • Hav u checked the fiddle link in his answer? Commented Jul 4, 2013 at 11:08

3 Answers 3

2

If you want to disable checkboxes with No answer option you can try this:

$('label:contains("No answer")').prev(':checkbox').prop('disabled', true);

http://jsfiddle.net/PUJrQ/

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

2 Comments

how can i disable it this way ? what am i doing wrong here.. $('#ddcl-ddlOutcomeList-ddw input:checkbox').each( function(e) { var chkBoxVal=$("label[for='" + $(this).attr("id") +"']").text().toLowerCase(); if (chkBoxVal == 'no answer' || chkBoxVal == 'left message' || chkBoxVal == 'engaged') { $(this).disabled(); console.log(chkBoxVal); }
You should use 'prop', not attr.
1
<input type="checkbox"  id="test"/>
<label for="test">THIS IS LABEL</label>

You can use $("label[for='test']")

Comments

0

Finally i found a way to do it by my self.

           $('#ddcl-ddlOutcomeList-ddw input:checkbox').each( function(e) {
        var  chkBoxVal=$("label[for='" + $(this).attr("id") +"']").text();
        console.log(chkBoxVal);
     });

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.