[Javascript] adding numerics in a table column

Peter Brunone peter at brunone.com
Wed Apr 18 09:36:50 CDT 2007


  

Hi DeWayne,

    I'm not familiar with the COL element, but I see a few problems here.

    First, your opening line in the sumup function doesn't assign the object to anything, so it's just being lost (making the line superfluous).  Not sure if that matters in your overall approach...

    Second, you are assigning an object (column) to the value of a form field.  You need to get the innerHTML (or innerText if you're just in IE) of the column and assign that to the value instead.  This will take care of the [object] problem you're having.

    Beyond that, getElementsByTagName does not get an element by its NAME attribute; instead, it gets all elements of that tag type.  For example, getElementsByTagName("SPAN") would get an array of all SPAN elements.  I suggest giving your objects ID attributes and using document.getElementById instead, since this will grab a reference to one and only one element.

Hope this helps...

Peter

--------------------------------------------------------------------------------
From: DeWayne Crenshaw <decren at yahoo.com>

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("Table4")
column = document.getElementsByTagName("colFour");
document.R2CDorder1.tbTotal.value = column;
}
.....

 
 
 
 
 
 
.....

onclick="sumup();"./>
.....But when I click pbTest, the result in tbTotal
is.....
[object]
.....What am I doing wrong?

The page is a work-in-progress so there is a lot of
garbage still on it but it is located at:

http://aaronzjukebox.com/R2CDorder1


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070418/3d961cfa/attachment.htm>


More information about the Javascript mailing list