473,467 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I want to sum values in rows and coloums of a table.

36 New Member
I want the result to be displayed at the last row and last colom of every row...

I have found this javascript code from somewhere.to do the same.. But the problem is . I am confused how should I call this function in my actual table rows and coloms...

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function sumup( o ) {
  3.  var t = [], cell,
  4.   row = document.getElementById( 'sumtable' ).rows,
  5.   i = row.length - 1,
  6.   lastrow = row[i];
  7.  while(i--) {
  8.   cell = row[i].cells; j = cell.length;
  9.   while(j--) {
  10.    if( !t[j] ) { t[j] = 0; }
  11.    t[j] += parseFloat( cell[j].firstChild.nodeValue ) || 0;
  12.   }
  13.  }
  14.  j = t.length; while(j--) {
  15.   if( lastrow.cells[j] ) { lastrow.cells[j].firstChild.nodeValue = t[j]; }
  16.  }
  17.  o.disabled = true;
  18. }
  19. </script>
I know that I to the table I have to give id = sumtable .. but wht should I do to get the result in the last row and table...

PLease please help me... as i m new to javascript and programmin
Sep 15 '09 #1
8 6137
Dormilich
8,658 Recognized Expert Moderator Expert
@tarunkhatri
call the function with the desired event. the function takes care of the rest.
Sep 15 '09 #2
tarunkhatri
36 New Member
Thanks for quick answer Dormilich. I am calling the function in the followin manner on the onchange event.. but is not working..

Expand|Select|Wrap|Line Numbers
  1. <table width="200" border="1" id = "sumtable">
  2. <tbody id = "sumtable>
  3.   <tr>
  4.     <td><input type="text" id="Row 1 colom 1" name="value1" value ="" size = "4"/ onChange = "sumup()"></td>
  5.     <td><input type="text" id="Row 1 colom 1" name="value2" value ="" size = "4" onChange = "sumup()"/></td>
  6.     <td><input type="text" id="Row 1 colom 1" name="value3" value ="" size = "4" onChange = "sumup()"/></td>
  7.     <td><input type="text" id="Row 1 colom 1" name="value4" value ="" size = "4" onChange = "sumup()"/></td>
  8.     <td><input type="text" id="answer" name="answer" value="" DISABLED/></td>
  9.   </tr>
  10.   <tr>
  11.     <td><input type="text" id="value1" name="value1" value ="0" size = "4" onChange = "sumup()"/></td>
  12.     <td><input type="text" id="value2" name="value2" value ="0" size = "4"/ onChange = "sumup()"></td>
  13.     <td><input type="text" id="value3" name="value3" value ="0" size = "4"/ onChange = "sumup()"></td>
  14.     <td><input type="text" id="value4" name="value4" value ="0" size = "4"/ onChange = "sumup()"></td>
  15.     <td><input type="text" id="answer" name="answer" value="" DISABLED/></td>
Sep 15 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
the programme expects to have the values to count as text of the table cells, not as input fields.

counting the values of input fields is much easier, because you can get the fields by a common name.

sumup() is missing the input parameter

PS. please use tags when posting code

PPS. the IDs in the first <tr> are invalid.
Sep 15 '09 #4
tarunkhatri
36 New Member
Hummm.... You are rgt I want the values to be input types .. and as soon as any value in the grid is changed I want the sum to e updated......

Even I want to get all the fields by common name.... But if u can please help me how can I set the parameter in sumup() which is missing and than call it in the actual HTML .. As today is only my second day with javascrpt to vry much confused...
Many Thanks
Sep 15 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
@tarunkhatri
then it’s best to read a tutorial, there are some links in the forum stickies.

@tarunkhatri
you need a different function because this function doesn’t fit your needs.
Sep 15 '09 #6
tarunkhatri
36 New Member
Ohh .. is it... I appriatiate your effort thanks very much..... But if you find a function thts does this job please reply...As I have a deadline of today from my boss :( ...
Sep 15 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
no need for me to search, I could write something as simple as that in probably 15 mins.
Sep 15 '09 #8
tarunkhatri
36 New Member
Can u please please do it for me .. If u have 15 mins ..It wud be a gr8 gr8 help for me .....
Sep 15 '09 #9

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

Similar topics

2
by: Caroline | last post by:
I seem to always want to do this type of join, but I can never find how to do this. I am trying to join two tables. The parent table will always have one row of data and the child may have 0 to...
3
by: eSapient | last post by:
I created a web page which contains a form which contains a table. The number of rows for the table are determined dynamically. The first cell of each row contains a HyperLink control and the last...
4
by: Jack | last post by:
THE FOLLOWING IS A PART OF CODE FROM A ASP PAGE <% sql01 = "SELECT COUNT(*) AS reccount FROM Equipmenttbl " sql01 = sql01 & "WHERE Equipmenttbl.GrantID = " & GrantID 'Response.Write sql01 &...
5
by: BLACKDOG157 | last post by:
I've made a form with a variable number of textboxes. The user fills them out, and then I need to pick up the values he has filled in. The number of textboxes vary depending on a value that the...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
7
gchq
by: gchq | last post by:
Hi there Here is the situation - a table is built dynamically with values in the cells I need to retrieve and enter into a database. I have found a way of getting values using JavaScript, but of...
8
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation
6
by: shira | last post by:
Hi, Looking to see if someone might have an explanation for this behavior. Is it a bug? Corruption? I have been able to reproduce the problem with only 2 rows and 1 field. Here is the table:...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.