Count the Rows which are checked [Resolved]

Posted by raghuavulapalli-25110 under jQuery on 1/9/2014 | Points: 10 | Views : 1575 | Status : [Member] | Replies : 2
Hi,

I came Here with this scenario.

Id Name IsChecked
----- --------- -------------
1 ABC []
1 ABC []
2 ABC []
3 DEF []
4 KLMN []

Id Name Count
----- --------- -------------
1 ABC 0
2 ABC 0
3 DEF 0
4 KLMN 0

There are two html tables as above. if check/uncheck on first table checkbox the count should be in the count field in table2 and increment/ decrement by 1. Observe that if there are duplicate columns the count must be increase for each check.

Please provide me Jquery code for this.

Raghunath


Responses

Posted by: kgovindarao523-21772 on: 1/9/2014 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

I Tried like this.
Here is the code.
$(document).ready(function ()
{
$('#table1 tr td').each(function ()
{
$(this).find('input:checkbox').click(function ()
{
var isChecked = $(this).attr('checked') ? true : false;
if (!isChecked)
{
$(this).attr('checked', 'checked');
var col1 = $(this).parents('tr').find('td:eq(0)').html();
var col2 = $(this).parents('tr').find('td:eq(1)').html();
$('#table2 tr').each(function ()
{
var col11 = $(this).find('td:eq(0)').html();
var col12 = $(this).find('td:eq(1)').html();
if (col11 != 'undefined' && col12 != 'undefined')
{
if (col1 == col11 && col2 == col12)
{
var cntObj = $(this).find('td:eq(2)').find('label');
var cnt = cntObj.html();
cntObj.html(parseInt(cnt) + 1);
}
}
});
}
else
{
$(this).removeAttr('checked');
var col1 = $(this).parents('tr').find('td:eq(0)').html();
var col2 = $(this).parents('tr').find('td:eq(1)').html();
$('#table2 tr').each(function ()
{
var col11 = $(this).find('td:eq(0)').html();
var col12 = $(this).find('td:eq(1)').html();
if (col11 != 'undefined' && col12 != 'undefined')
{
if (col1 == col11 && col2 == col12)
{
var cntObj = $(this).find('td:eq(2)').find('label');
var cnt = cntObj.html();
cntObj.html(parseInt(cnt) - 1);
}
}
});
}
});
});
});


Thank you,
Govind

raghuavulapalli-25110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: raghuavulapalli-25110 on: 1/9/2014 [Member] Starter | Points: 25

Up
0
Down
Its working fine.
Thank you...

Raghunath

raghuavulapalli-25110, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response