Get table cell values when checkbox is check

Hey guys I just need help with some jquery stuff,

How can I get the sum of cell values that is checked after submitting the form…

here’s the basic html that I have…

      <th>ADD </th>
      <th>Value </th>
     <td><input type="checkbox" name="check_data"></td>
      <td class="num"> 2 </td>
     <td><input type="checkbox" name="check_data"></td>
      <td class="num"> 3 </td>
     <td><input type="checkbox" name="check_data"></td>
      <td class="num"> 4 </td>
    <input type="submit" name="addValues" class="addValue" >



I want to get the cell that has a class of num
after I checked the checbox cell

please help me…

the only I can do is get the sum of values of the cell without checking the checkbox, its complicated since Im still learning jquery

$('.addValue').click(function() {
var text = 0;
 $('table td.num').each(function()
   text += parseInt($(this).text() );


any help will be much appreciated :slight_smile:

I’ve never used JQuery, but I suspect the issue is that you are not checking the CHECKED status of the checkboxes - you are just adding the numbers regardless. :slight_smile:

how can I checked the status?any hints

This is what you’ll need. I’ve commented so you can see what’s happening. jQuery is a beautiful thing :wink:

	// Attach a click handler
	// The function that tallies the checked values
	function tallyValues(){
		// Set the amount to start at 0
		var amount = 0;
		// Loop through each dom element
		$('table .num').each(function(i, val){
			// Find the previous sibling (td) and then find the input inside and see if it's checked
			var checkbox_cell_is_checked = $(this).prev().find('input').is(':checked');
			// Is it checked?
				amount += parseInt($(this).text())
		// Output the amount

thanks! jboesch for the help… :slight_smile: