On Wed, 14 Mar 2007, Dave Raggett wrote:
>
> What I haven't yet worked out is how to address the fields in each row
> from the onforminput event handler set on the form element.
>
> [...]
> alert("rows = " + form.row[0].item.value);
That should be "form["row0.item"].value".
The [foo] bit in the name="" attributes get expanded, so that the names
are "row0.item", "row1.item", etc; the actual repetition blocks don't have
the square brackets. Look at the post-repetition DOM to see what I mean.
(The square-bracket dereference notation is required because there's a "."
in the name of the field.)
Anyway, you just want:
Total price: 0
...with:
function total() {
var rows = document.getElementsByTagName('tbody')[0].rows;
var result = 0;
for (var i = 0; i < rows.length; ++i) {
var prefix = 'row' + rows[i].repetitionIndex;
result += rows[i].getElementsByName(prefix + 'quantity')[0].value *
rows[i].getElementsByName(prefix + 'unitprice')[0].value;
}
return result;
}
By the way, the [EMAIL PROTECTED] mailing list is probably more appropriate
for this thread. (That's our authoring help mailing list.)
HTH,
--
Ian Hickson U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/ U+263A/, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'