Sunday 15 April 2012

checkbox - jQuery if or while loops -


I have not done much (or none) jQuery I got the following script here, but I have a question. While searching this site, I have tried all those efforts to ruin the script. I only want to add the values ​​of other columns to it if the checkbox is checked.

Here's an example table:

  & lt; Table id = "sum_table" class = "example" & gt; & Lt; Thead & gt; & Lt; Tr class = "titlerow" & gt; & Lt; Td square = "table-sorted: numerical" & gt; Apple & lt; / Td> & Lt; Td square = "table-sorted: numerical" & gt; Orange & lt; / Td> & Lt; Td square = "table-sorted: numerical" & gt; Watermelon & lt; / Td> & Lt; Td square = "table-sorted: numerical" & gt; Turtle & lt; / Td> & Lt; / TR & gt; & Lt; / Thead & gt; & Lt; TR & gt; & Lt; Td class = "rowDataSd" & gt; 52 & lt; / Td> & Lt; Td class = "rowDataSd" & gt; 911 & lt; / Td> & Lt; Td class = "rowDataSd" & gt; 911 & lt; / Td> & Lt; Td> & Lt; Input type = "checkbox" name = "CB" value = "1" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td class = "row data sd" & gt; 989 & lt; / Td> & Lt; Td class = "rowDataSd" & gt; 24 & lt; / Td> & Lt; Td class = "rowDataSd" & gt; 911 & lt; / Td> & Lt; Td> & Lt; Input type = "checkbox" name = "CB" value = "1" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td class = "row data sd" & gt; 989 & lt; / Td> & Lt; Td class = "rowDataSd" & gt; 911 & lt; / Td> & Lt; Td class = "rowDataSd" & gt; 911 & lt; / Td> & Lt; Td> & Lt; Input type = "checkbox" name = "CB" value = "1" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; Tfoot & gt; & Lt; Tr class = "totalColumn" & gt; & Lt; Td square = "total call" & gt; Total: & lt; / Td> & Lt; Td square = "total call" & gt; Total: & lt; / Td> & Lt; Td square = "total call" & gt; Total: & lt; / Td> & Lt; Td square = "total call" & gt; Total: & lt; / Td> & Lt; / TR & gt; & Lt; / Tfoot & gt; The script here is:  
  $ ('# sum_table tr: first td'). Each (function () {var $ td = $ (this); var colTotal = 0; $ ('# sum_table tr: not (: first, .totalColumn)'). Each (function () {colTotal + = parseInt ($ (This). Children (). Eq ($ td Index ()) .HTML (), 10);}); $ ('# sum_table tr.totalColumn') Children (). Eq ($ td.index ( )). Html ('Total:' + Vertical);});   

Where do I keep & amp; Amp;, and what exactly will be & amp; Amp; It is possible?

I tried to add and amp; but I'm still not familiar with how to read jQuery. I would love to learn it and I thought it would be a simple project. Not estimation As always, any help is greatly appreciated.

Try it out:

Very simple version.

  $ ('[name =' cb ']'). Change (function () {// your check box $$ ('total.column td: lt (3)' '.html ("0"); // TDS to the deposit amount is 0 $ (' '[name = Cb "]: checked '). The closest (' tr '). (' Td: lt 3) '). Every (function () () (All checks checkboxes var $ td = $ (this); var $ sumColumn = $ (Loop through all TDS (but the last one) for the lines of '# sum_table tr.totalColumn) Td: eq (' + $ td.index () + ');) Current TD revision var currVal = $ sumColumn Get the Notification column in the Total checkbox relative to .html () || There is no default price for the 0 currVal = + currVal + $ td.html (); // value $ sumColumn.html (currVal); // Populate the column in the total checkbox relative to current TD}}}}            

No comments:

Post a Comment