473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sum of Table Row using javascript

1 New Member
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 1631
Claus Mygind
571 Contributor
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
3490
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 help me out with a snippet of code. Thanks in advance Chansiboy
2
2292
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 AssayType="DNA" AssayNumber="3"> <Sample> <Destination Position="D2"/> <Source SourcePlate="P3" SourcePos="A2" sourceConc=2"/> </Source>
5
7600
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 advance.
4
3103
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 calculate as such in that formula n display in the price1 text using the text property onblur,
3
4844
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 taking the value of each table individually thats i am not able to get any value. if i get the value of table then its not taking properly. let...
6
7707
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 table that starts like this: 11 12 13 21 22 23 31 32 33 41 42 43 The html has no id's or spans or divs to work with and I cannot...
1
7981
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 are inserted in a table (but it doesn't work)a new row is inserted and in this rows are exported the data from form. thank you in advance <html>...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.