0

What I want is when checkbox1 is selected both checkbox labelled 1 will get selected and background will be removed

here is the fiddle

for eg if i select checkbox1 it should select both checkbox labelled checkbox1

3
  • 1
    How long did you spend formatting that question? < 10 seconds? Commented Sep 22, 2011 at 13:07
  • i thought the question i wrote in Word Format will maintain the formatting Commented Sep 22, 2011 at 13:09
  • 1
    Almost never cut-and-paste from a word processor into something expecting plain text. Stick to plain text, and use the formatting provided by the site :) Commented Sep 22, 2011 at 13:16

3 Answers 3

3

The problem is that searching for ID $("#somethin") is not possible to select more than one element. IF you search for class, then your example works.. well, with some minor changes :)

$(document).ready(function() {
  $('input[type=checkbox]').change(function(){
        var pos;
        pos = this.id;

       // global hook - unblock UI when ajax request completes
        $(document).ajaxStop($.unblockUI);


        if($(this).prop("checked")) {
            $("."+pos).parent().removeClass("highlight");
            $("."+pos).prop('checked', true)

            //ajax to add uni
        } else {
            //ajax to remove uni
            $("."+pos).parent().addClass("highlight");
            $("."+pos).prop('checked', false)


        }
    });

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

2 Comments

agreed... your comments did help me figure out my problem +1 , accepted answer
(Yours is more generic than mine, +1 :)
0

You can't have multiple DOM elements with the same id.

See this fiddle for a working example, but it's not as generic as you may need.

Comments

0

Select multiple elements using class. You can try this..

<script language="javascript" type="text/javascript">
     $(function () {
         $("#checkbox1").click(function () {
             $('.case').attr('checked', this.checked);
         });
     });
</script>

and your html code will be like below

<div>
   <table>
<tr>
    <td><input type="checkbox" id="checkbox1" class="highlight"/></td>
    <td>Item1</td>
    <td>value</td>
</tr>
<tr>
    <td align="center"><input type="checkbox" class="case" name="case" value="1"/></td>
    <td>Item2</td>
    <td>value</td>
</tr>

</table>
    </div>

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.