473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sum of Table Row using javascript

HI I am In the finishing stage of this project, but this wall stands in front of me...I have table which displays data from the database, using forloop and arraylist variables.. and the user enters one col value which is left empty(I have given it all as Input edit box to edit if required) and the last col should show the result of that particular row..Please Help me...


Expand|Select|Wrap|Line Numbers
  1.     <table id="results" border="1" width="100%"> <tr> <th align="center">Sl No</th> <th align="center">PName</th> <th align="center">Pcode</th> <th align="center">OB</th> <th align="center">Receipt</th> <th align="center">Total</th> <th align="center">Price</th> <th align="center">Closing Balance</th> <th align="center">Amount</th> </tr> <tr> <%
  2.                         int count=0;
  3.  
  4.                             for (int i = 0; i < pc.size(); i++) {
  5.  
  6.                                 Object[] p = new Object[pc.size()];
  7.                                 Object[] n = new Object[pc.size()];
  8.                                 Object[] o = new Object[pc.size()];
  9.                                 Object[] r = new Object[pc.size()];
  10.  
  11.                                 Object[] pr = new Object[pc.size()];
  12.                                 Object[] t = new Object[pc.size()];
  13.  
  14.                                 p[0] = pc.get(i);
  15.                                 n[0] = pn.get(i);
  16.                                 o[0] = A_ob.get(i);
  17.                                 r[0] = A_receipt.get(i);
  18.  
  19.                                 pr[0] = A_price.get(i);
  20.                                 t[0] = A_tot.get(i);
  21.  
  22.  
  23.  
  24.                         %> <td align="center"><%=i+1 %></td> <td align="center"><input type="edit" name="pname" value="<%=pn.get(i)%>"  readonly> </td> <td align="center"><input type="edit" name="pcode" value="<%=pc.get(i)%>" readonly></td> <td align="center"><input type="edit" name="ob" value="<%=A_ob.get(i)%>" readonly></td> <td align="center"><input type="edit" name="receipt" value="<%=A_receipt.get(i)%>" readonly></td> <td align="center"><input type="edit" name="total" value="<%=A_tot.get(i)%>" readonly></td> <td align="center"><input type="edit" name="price" value="<%=A_price.get(i)%>" readonly></td> <td align="center"><input type="edit" name="close" id="<%=i%>" value=''></td> <td align="center"><input type="edit" name="total" value="0" readonly></td> </tr> <%
  25.                         }
  26.                     %> </table>
Nov 7 '14 #1
1 1629
Claus Mygind
571 512MB
Expand|Select|Wrap|Line Numbers
  1. var dataArrayToBeStreamed;
  2.  
  3. //add table to form
  4. //this could be pre-defined when the form is streamed out.
  5. //just add a <tbody></tbody> tag to the table so you can reference it.
  6. document.getElementById("formOnWhichTableIsDisplayed").innerHTML = '<table id="results" border="1" width="100%"><tbody id="resultsBody"></tbody></table>'; 
  7.  
  8. for (var i = 0; i < dataArrayToBeStreamed.length; i++ )
  9. {
  10.     // step 1 add row to table
  11.     tr = tbody.insertRow(tbody.rows.length);
  12.  
  13.     // step 2 add cells to this row
  14.     td = tr.insertCell(tr.cells.length);
  15.  
  16.     // step 3 add content to cell
  17.     td.setAttribute("align", "center");
  18.     td.innerHTML =    '<input'+
  19.                     ' type="text"'+ 
  20.                     ' id="Quantity'+i+'"'+
  21.                     ' maxLength=6' 
  22.                     ' size=5'
  23.                     ' onChange="calcTotal('+i+');"'+
  24.                     ' />';
  25. //repeat steps 2 and 3 for additonal cells
  26.  
  27. //repeat step 1 for additonal rows, then follow with steps 2 and 3 to fill in row
  28.  
  29. }
  30.  
  31. function calcTotal(rowNumber) 
  32. {
  33.     //getting the row number from the onChange handler you can now do the calc on this row.
  34.     document.getElementById("Total"+rowNumber).value = document.getElementById("Quanity"+rowNumber).value * document.getElementById("Price"+rowNumber).value;
  35.  
  36. }
  37.  
Dec 8 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: chansiboy | last post by:
Hi, I've developed a jsp page, where in i had a table getting list of data. I want the table header to be fixed, and i should allow scrolling only for the data in the table. Can anyone please...
2
by: Bogey | last post by:
Hi, I am newby in Xml I want to build a table that i can later manipulate in javascript The Sample.xml contains several Assay with varying number of sample; it looks like that <Assay...
5
by: Hari2005 | last post by:
I try to get width of a table using javascript. Table width is not defined in table. It grows as per the data. Please suggest how to get table width using javascript at run time??????? Thanks in...
4
by: sureshl | last post by:
function cal() { var f = document.form1; var regExp_Count = new RegExp("^+$"); f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0); } cal() functions , will...
3
by: tokcy | last post by:
hi everyone, i am creating dynamic row in a table using javascript its working fine and now i want to create more than 1 table using javascript which is dynamic its also working fine but when i am...
6
shelzmike
by: shelzmike | last post by:
As mentioned, I am new to Javascript and have been given an assignment that to me seems way outside the normal scope of what I would ever do in the real world, but nonetheless, here goes. I have a...
1
by: Andrei Stan | last post by:
hello, could anyone help me? i am a beginer in java script and i want to put data from the form into a existing table and for every set of value fill in the text boxes of the form when these data...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.