"Greg" <gr********@yah oo.com> wrote in message
news:38******** *************** ***@posting.goo gle.com...
I have the following code (a one line function)
I'm trying to calculate a value for text field matPerPiece#
where # is a row number I provide. The value is calculated
from text fields matPOTotal# and QuantityMade.
The elements exist in a form named costsheet
function mattotalrow(row Number) {
document.getEle mentsById('matP erPiece' + rowNumber).valu e =
(document.getE lementsById('ma tPOTotal' + rowNumber) /
document.getEl ementsById('Qua ntityMade'));
}
I'm not sure how to access the values in the object that
is returned by the following syntax:
var newObj = document.getEle mentsById('fiel dname');
Thanks for your help I appreciate any suggestions you can provide.
Given a form named 'costsheet' and an element who's name is an integer
concatenated to the end of 'matPerPiece', the code W3C HTML DOM Level 2
standard (and very back-compatible) property accessor:-
document.forms['costsheet'].elements['matPerPiece'+r owNumber]
- would be the best way of construction a global reference to a from
element.
Properties of that element would normally be accessed with dot notation,
adding, say - .value - to the end of the above reference to access the
"value" property of the element.
It is however more efficient to cache references to objects that
represent stages in repeated property accessors, such as a reference to
the form or the form's elements collection. I assume that the function
above is intended to read the value in the second two elements and
assign the result of the calculation to the value property of the first,
so something like:-
function mattotalrow(row Number){
var els = document.forms['costsheet'].elements;
els['matPerPiece'+r owNumber].value =
(els['matPOTotal'+ro wNumber].value /
els['QuantityMade'+ rowNumber].value);
}
Richard.