Add data from an html table

Asked

Viewed 60 times

1

I would like to present the total value and not NAN...

function sumQuantity() {

  var elements = document.getElementsByClassName('itemTable');
  var sum = 0;

  for (i = 0; i < elements.length; i++) {
    sum = sum + parseFloat(elements[i].innerHTML);
  };

  alert(sum);


}

sumQuantity();
<table class="itemTable" cellspacing="0" rules="all" border="1" id="OrdersDataGrid" style="border-collapse:collapse;margin-right:10px;">
  <tbody>
    <tr style="background-color:#E8E8E8;">
      <td class="itemTableHeader itemTableHeader-Id">Pedido</td>
      <td class="itemTableHeader itemTableHeader-Date">Criado</td>
      <td class="itemTableHeader itemTableHeader-Items">Itens</td>
      <td class="itemTableHeader itemTableHeader-Proof">Prova</td>
      <td class="itemTableHeader itemTableHeader-Price">Preço total</td>
      <td class="itemTableHeader itemTableHeader-Status">Status</td>
      <td class="itemTableHeader itemTableHeader-Options">Opções</td>
    </tr>
    <tr class="48 G-CDC2B78C">
      <td class="itemTable       itemTable-Id">G‑CDC2B78C</td>
      <td class="itemTable       itemTable-Date">23/03/2018 12:00</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl03_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl03$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="46 G-CDB4B78C">
      <td class="itemTable       itemTable-Id">G‑CDB4B78C</td>
      <td class="itemTable       itemTable-Date">23/03/2018 11:56</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl04_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl04$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="33 G-CDB7B78D">
      <td class="itemTable       itemTable-Id">G‑CDB7B78D</td>
      <td class="itemTable       itemTable-Date">21/03/2018 17:29</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl05_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl05$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="27 G-CDB3B78E">
      <td class="itemTable       itemTable-Id">G‑CDB3B78E</td>
      <td class="itemTable       itemTable-Date">21/03/2018 15:28</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 011 – Cupom Bio Running 50% de desconto</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 78,00</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl06_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl06$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="22 G-CDB8B78E">
      <td class="itemTable       itemTable-Id">G‑CDB8B78E</td>
      <td class="itemTable       itemTable-Date">21/03/2018 12:07</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 012 – Flyer BioNurtri Divulgação</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 33,00</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl07_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl07$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="16 G-CDB4B78F">
      <td class="itemTable       itemTable-Id">G‑CDB4B78F</td>
      <td class="itemTable       itemTable-Date">20/03/2018 17:52</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 003 – CARTÃO DE VISITA BIORITMO SMARTFIT FITNESSCHANNEL</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl08_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl08$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="13 G-CDB7B78F">
      <td class="itemTable       itemTable-Id">G‑CDB7B78F</td>
      <td class="itemTable       itemTable-Date">20/03/2018 17:23</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 002 – CARTÃO DE VISITA BIORITMO SMARTFIT</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl09_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl09$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="9 G-CDCAB797">
      <td class="itemTable       itemTable-Id">G‑CDCAB797</td>
      <td class="itemTable       itemTable-Date">20/03/2018 17:00</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl10_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl10$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="6 G-CDCAB78A">
      <td class="itemTable       itemTable-Id">G‑CDCAB78A</td>
      <td class="itemTable       itemTable-Date">20/03/2018 16:49</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl11_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl11$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
    <tr class="4 G-CDCAB78C">
      <td class="itemTable       itemTable-Id">G‑CDCAB78C</td>
      <td class="itemTable       itemTable-Date">20/03/2018 16:48</td>
      <td class="itemTable       itemTable-Items">
        <p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p>
      </td>
      <td class="itemTable       itemTable-Proof">
        <p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p>
      </td>
      <td class="itemTable       itemTable-Price">R$ 35,50</td>
      <td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td>
      <td class="itemTable       itemTable-Options">
        <a id="OrdersDataGrid_ctl12_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl12$Linkbutton3','')">Detalhes</a>
      </td>
    </tr>
  </tbody>
</table>

  • This table is dynamic or static?

  • Hello Leandro the table is dynamic

  • The data that fill the table comes as, Ajax?

  • This is an aspx an application called pageflex Storefront, I honestly don’t know how it comes ... there is some way I know ?

  • Cara you can know by the console, anyway, returning to the question, a way for you to get the total value of prices would be you put an id on each line where the price goes and take the value and add up everything.

  • Okay, it’s just that I can’t change this code because it’s closed..

  • When you changed the class name to "td.itemTable-Price" , it returns 0 var Elements = Document.getElementsByClassName('td.itemTable-Price');

  • Even if someone has a better solution than this ...>> thank you

Show 3 more comments

2 answers

0

Dude I’m a little out of time on the job so I did kind of fast, it’s a way to do, there are others, even more elegant, I used jQuery, see if this code meets you

  
  //var elements = document.getElementsByClassName('itemTable');
  var sum = 0;

  /* for (i=0;i< elements.length;i++) {
      sum = sum + parseFloat(elements[i].innerHTML);
     }; */
     
     var preco1 = parseFloat($('#preco1').text());
     var preco2 = parseFloat($('#preco2').text());
     var preco3 = parseFloat($('#preco3').text());
     var preco4 = parseFloat($('#preco4').text());
     var preco5 = parseFloat($('#preco5').text());
     var preco6 = parseFloat($('#preco6').text());
     var preco7 = parseFloat($('#preco7').text());
     var preco8 = parseFloat($('#preco8').text());
     var preco9 = parseFloat($('#preco9').text());
     var preco10 = parseFloat($('#preco10').text());
     
     sum = preco1 + preco2 + preco3 + preco4 + preco5 +
     preco6 + preco7 + preco8 + preco9 + preco10;
          
    
   alert(sum);
    
   
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="itemTable" cellspacing="0" rules="all" border="1" id="OrdersDataGrid" style="border-collapse:collapse;margin-right:10px;">
	<tbody><tr style="background-color:#E8E8E8;">
		<td class="itemTableHeader itemTableHeader-Id">Pedido</td><td class="itemTableHeader itemTableHeader-Date">Criado</td><td class="itemTableHeader itemTableHeader-Items">Itens</td><td class="itemTableHeader itemTableHeader-Proof">Prova</td><td class="itemTableHeader itemTableHeader-Price">Preço total</td><td class="itemTableHeader itemTableHeader-Status">Status</td><td class="itemTableHeader itemTableHeader-Options">Opções</td>
	</tr><tr class="48 G-CDC2B78C">
		<td class="itemTable       itemTable-Id">G‑CDC2B78C</td><td class="itemTable       itemTable-Date">23/03/2018 12:00</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco1"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl03_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl03$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="46 G-CDB4B78C">
		<td class="itemTable       itemTable-Id">G‑CDB4B78C</td><td class="itemTable       itemTable-Date">23/03/2018 11:56</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco2"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl04_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl04$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="33 G-CDB7B78D">
		<td class="itemTable       itemTable-Id">G‑CDB7B78D</td><td class="itemTable       itemTable-Date">21/03/2018 17:29</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco3"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl05_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl05$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="27 G-CDB3B78E">
		<td class="itemTable       itemTable-Id">G‑CDB3B78E</td><td class="itemTable       itemTable-Date">21/03/2018 15:28</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 011 – Cupom Bio Running 50% de desconto</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco4"> 78,00</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl06_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl06$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="22 G-CDB8B78E">
		<td class="itemTable       itemTable-Id">G‑CDB8B78E</td><td class="itemTable       itemTable-Date">21/03/2018 12:07</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 012 – Flyer BioNurtri Divulgação</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco5"> 33.00</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl07_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl07$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="16 G-CDB4B78F">
		<td class="itemTable       itemTable-Id">G‑CDB4B78F</td><td class="itemTable       itemTable-Date">20/03/2018 17:52</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 003 – CARTÃO DE VISITA BIORITMO SMARTFIT FITNESSCHANNEL</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco6"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl08_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl08$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="13 G-CDB7B78F">
		<td class="itemTable       itemTable-Id">G‑CDB7B78F</td><td class="itemTable       itemTable-Date">20/03/2018 17:23</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 002 – CARTÃO DE VISITA BIORITMO SMARTFIT</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco7"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl09_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl09$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="9 G-CDCAB797">
		<td class="itemTable       itemTable-Id">G‑CDCAB797</td><td class="itemTable       itemTable-Date">20/03/2018 17:00</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco8"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl10_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl10$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="6 G-CDCAB78A">
		<td class="itemTable       itemTable-Id">G‑CDCAB78A</td><td class="itemTable       itemTable-Date">20/03/2018 16:49</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco9"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl11_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl11$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr><tr class="4 G-CDCAB78C">
		<td class="itemTable       itemTable-Id">G‑CDCAB78C</td><td class="itemTable       itemTable-Date">20/03/2018 16:48</td><td class="itemTable       itemTable-Items"><p class="itemTableLabelWithIcon"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> 001 – CARTÃO DE VISITA BIORITMO</p></td><td class="itemTable       itemTable-Proof"><p class="proofLinks"><img align="absmiddle" width="18px" height="18px" src="Images/space.gif"> </p></td><td class="itemTable       itemTable-Price" id="preco10"> 35.50</td><td class="itemTable       itemTable-Status"><img align="absmiddle" src="Images/OrderInProcessStatusIcon.png">&nbsp;Em processo</td><td class="itemTable       itemTable-Options">
                     <a id="OrdersDataGrid_ctl12_Linkbutton3" class="siteLink" name="Linkbutton1" href="javascript:__doPostBack('OrdersDataGrid$ctl12$Linkbutton3','')">Detalhes</a>
                 </td>
	</tr>
</tbody></table>

Note that I took the R$ and exchanged the , for . in html, but, da para fazer isto com expressão regular.

  • Thanks Leandro for the effort >>>> But as I said I can’t change the values But the Icaro below solved the puzzle.... Thank you very much

  • Oops, settled there for you, it’s worth man! Success.

0


See if the change I made helps you.

I basically started using the class of TD that contains the values itemTable-Price and made a replace in the text to turn into float

function sumQuantity() 
{
    var elements = document.getElementsByClassName('itemTable-Price');
    var sum = 0;

    for (i=0;i< elements.length;i++) 
    {
        sum += parseFloat(elements[i].innerHTML.replace(/,/,'.').replace('R$',''));
    };

    alert(sum);
}

https://jsfiddle.net/hmpwvgux/37/

  • Thanks Icaro besides helping gave a lesson >>>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.