javascript - Add checked cell in a table using jquery -


i have tried add cell number in table. want add on cell checked (using check box). want using javascript

/here code/

<html>     <head>     </head>     <body> <form name="addvalue">         <table id="countit" border="1px">             <tr>        <td><input type="checkbox" name="choice"/></td>         <td>some value</td>         <td>some value</td>                 <td class="count-me">12</td>              </tr>             <tr>         <td><input type="checkbox" name="choice"/></td>         <td>some value</td>         <td>some value</td>                 <td class="count-me">2</td>              </tr>             <tr>         <td><input type="checkbox" name="choice"/></td>         <td>some value</td>         <td>some value</td>                 <td class="count-me">17</td>              </tr>         </table>     </form>          <script language="javascript" type="text/javascript">     function myfunction()     {             var tds = document.getelementbyid('countit').getelementsbytagname('td');              var sum = 0;             for(var = 0; < tds.length; ++) {                 if(tds[i].classname == 'count-me'){                     sum += isnan(tds[i].innerhtml) ? 0 : parseint(tds[i].innerhtml);                 }             }         document.getelementbyid('countit').innerhtml += '<tr><td>' + sum + '</td><td>total</td></tr>';      }            </script> <button onclick="myfunction()">click me</button>     </body> </html> 

modifiying js can that

 myfunction = function()     {             var tds = document.getelementsbyname('choice');             var values = document.getelementsbyclassname('count-me');               var sum = 0;              for(var = 0; < tds.length; ++) {                 if(tds[i].checked){                   sum+= parseint(values[i].innerhtml);                 }                  }       document.getelementbyid('countit').innerhtml += '<tr><td>' + sum + '</td><td>total</td></tr>';      } 

https://jsfiddle.net/79yf5to4/

search name instead of element td. if want search element have search row , after td.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -