Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2007, 07:46 AM
Registered User
 
Join Date: Mar 2007
Location: BOONEVILLE, MS, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding column numbers

Hello,
I have a table with an add-row setup. The table has several columns but I only need to calculate COLUMN FOUR. The results go to a textbox via a button. My code is.....

function sumup() {
 document.getElementById("Table1")
  column = document.getElementsByTagName("colFour");
  document.myForm.tbTotal.value = column;
}
.....
<TABLE NAME="Table1" id="Table1">
<COL WIDTH=10*>
    <COL WIDTH=139*>
    <COL WIDTH=27*>
    <COL WIDTH=29*>
    <COL WIDTH=27* NAME="colFour" id="colFour">
    <COL WIDTH=10*>
.....
<INPUT TYPE=TEXT NAME="tbTotal">
<INPUT TYPE=BUTTON NAME="pbTest" VALUE="TEST" onclick="sumup();"./>
.....But when I click pbTest, the result in tbTotal is.....
[object]
.....What am I doing wrong?



decren
Reply With Quote
  #2 (permalink)  
Old April 17th, 2007, 09:27 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

getElementsByTagName retrieves elements by tag name, your table will have rows of tr with cells of td. You need something like:
Code:
var oTable = document.getElementById("Table1");
var colRows = oTable.rows;
var dTotal = 0.0;
for (var i = 0; i < colRows.length; i++)
{
  var oRow = colRows[i];
  var oCell = oRow.cells[3];
  dTotal += //get data from cell, you haven't shown how it's held...
}
alert(dTotal);
--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old May 5th, 2007, 07:48 AM
Registered User
 
Join Date: Mar 2007
Location: BOONEVILLE, MS, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you joefawcett for the code. I played around with it a little but couldn't get it tweaked just right. But you did give me some ideas which I used to tweak a table I found at:
http://4umi.com/web/javascript
Again, thanx for the input.

decren
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding numbers in #.###,0 format margreta XSLT 6 April 25th, 2006 09:52 AM
Adding numbers Hudson40 Excel VBA 3 November 23rd, 2005 03:02 AM
adding numbers gmoney060 Access 1 August 15th, 2004 08:14 PM
Adding numbers kend XSLT 4 June 27th, 2003 12:33 AM
Adding numbers kend XSLT 1 June 26th, 2003 10:14 AM



All times are GMT -4. The time now is 08:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.