php - sum of element in a table jquery -


i've php file create table this

<table style="text-align:center; margin-top:20px;" align="center" cellpadding="5">  <caption><u><b>ordine del 22-10-2015 delle ore 16:08:38<b/></u><br /></caption>  <thead style="background-color:#ebe9e9">  <tr>      <th scope="col">prodotto</th>      <th scope="col">quantit&agrave;</th>      <th scope="col">prezzo</th>      <th scope="col">totale parziale</th>  </tr>  </thead>  <tbody style="background-color:f5ffff">  <tr>      <td>coca cola</td>      <td> x1</td>      <td>1,50 &euro;</td>      <td>1,50 &euro;</td>      <td><input type="hidden" class="toadd" value="1.50"></td> </tr><tr>      <td>limonata</td>      <td> x1</td>      <td>1,50 &euro;</td>      <td>1,50 &euro;</td>          <td><input class="toadd" type="hidden" value="1.50"></td>     </tr><tr>      <td>maxibon</td>      <td> x1</td>      <td>2,00 &euro;</td>      <td>2,00 &euro;</td>          <td><input class="toadd" type="hidden" value="1.50"></td>     </tr><tr>      <td>pirulo</td>      <td> x1</td>      <td>1,00 &euro;</td>      <td>1,00 &euro;</td>      <td><input class="toadd" type="hidden" value="1.50"></td>     </tr>     <tr>     <td colspan="2">totale</td>     <td colspan="2" class="totale"></td>     </tr>     </tbody></table>  

now php file create more , more table depending on row presents in bd

i use jquery code calculate sum of element class="toadd"

$(document).ready(function(){  var sum = 0;  $('.toadd').each(function() {     sum += number($(this).val()); });  $('.totale').text(sum.tolocalestring('it-it', { style: 'currency',  currency: 'eur',  minimumfractiondigits: 2  })); 

the problem when there's 1 table works perfect, when tables more one, gives me total of table.

i need total each table

try iterate tables , traverse each table element calculate/set values,

$("table").each(function(){    $('.toadd', this).each(function() {      sum += number($(this).val());    });   $('.totale', this).text(sum.tolocalestring('it-it', {     style: 'currency',      currency: 'eur',      minimumfractiondigits: 2    })); }); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -