473,385 Members | 2,180 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,385 software developers and data experts.

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

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 6134
Dormilich
8,658 Expert Mod 8TB
@tarunkhatri
call the function with the desired event. the function takes care of the rest.
Sep 15 '09 #2
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 Expert Mod 8TB
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
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 Expert Mod 8TB
@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
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 Expert Mod 8TB
no need for me to search, I could write something as simple as that in probably 15 mins.
Sep 15 '09 #8
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:...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.