tags:

views:

176

answers:

4

This is how my table structure looks,

 <table>
    <tbody>   
    <tr>
    <td id="**SelectCheckBox**" class="helpBod">
    <input id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl01_CheckBox0" type="checkbox"  name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl01$CheckBox0"/>
    </td>
    <td>
    </td>
    </tr>
    <tr>
    <td id="**SelectCheckBox**" class="helpBod">
    <input id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl02_CheckBox1" type="checkbox"  name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl02$CheckBox1"/>
    </td>
   <td>
    </td>
    </tr>
    <tr>
    </tbody>
</table>

I have a button SelectAll im going to call a jquery function to check mark all the checkbox

function look this

function jqCheckAll() {
        $("td#" + 'SelectCheckBox' + 'input:checkbox').attr('checked', true);

      }

problem is this will check mark only only checkbox what if i have 100 checkbox, i want to check mark all the this 100 checkbox on click of select all button.

+3  A: 

First, I can't really tell what you mean by "SelectCheckBox"; you cannot give all your checkboxes the same "id" value.

To check all the checkboxes in all the "helpBod" td elements, just do this:

$('td.helpBod input:checkbox').attr('checked', true);
Pointy
giving the same name or id will result in array in DOM right.
sameer
Well yes, but you definitely should not do that. It will confuse libraries like jQuery. The "id" is supposed to be the *identifier*, and it does not make sense for two different things to have the same identifier. Use a "class" value if you need multiple elements to be similar.
Pointy
+3  A: 
function jqCheckAll() {
    $("input:checkbox").attr('checked','checked');
}

Update, only checking in a single column:

Assuming your select_all button is inside the same td as the checkboxes, just do this:

$('td.helpBod .select_all').click(function(e){
    e.preventDefault();
    $(this).closest('td.helpBod').find(':checkbox').attr('checked', 'checked');
});

Again, that assumes your HTML looks something like this (the select_all doesn't have to be a button):

<td class="helpBod" ... >
  <button class="select_all">Select All</button>
  <input type="checkbox" ... />
  <input type="checkbox" ... />
  <input type="checkbox" ... />
  <input type="checkbox" ... />
</td>
Doug Neiner
thanks for details,but if i add one more check box in other column even that will be checked.i want only column of interest to be checked.
sameer
Will the down voter please explain?
Doug Neiner
Thanks doug for ur inputs appreciated.
sameer
+1  A: 

If I understand what youre asking the easiest way to do that would be

$('.helpBod input:checkbox').attr('checked','checked');

This only checks the ones you have that class on, so you wont affect other checkboxes you might have elsewhere.

Mech Software
+1  A: 

@sameer, what you want to do is add a class to all the checkboxes you want checked. Here I added a class "checkall" to the checkboxes that will be checked.

<input type="button" name="checkit" id="checkit" value="Check All">

 <table>
    <tbody>   
    <tr>
    <td>
    <input type="checkbox" class="checkall" name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl01$CheckBox0" id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl01_CheckBox0" />
    </td>
    <td>
    <input type="checkbox" name="chk1" id="chk1" />
    </td>
    </tr>
    <tr>
    <td>
    <input type="checkbox" class="checkall" name="TimeSheetWebUserControl1$TimeSheetRepeater$ctl02$CheckBox1" id="TimeSheetWebUserControl1_TimeSheetRepeater_ctl02_CheckBox1" />
    </td>
    <td>
   <input type="checkbox" name="chk2" id="chk2" />
    </td>
    </tr>
    <tr>
    </tbody>
</table>

The jQuery is then simple.

$('#checkit').click(function() {
    $('input:checkbox.checkall').attr('checked','checked');
    return false;
});
nolabel