Steven Cote wrote:
Woops, that's my fault. This is what I get for typing it out instead of
cut/pasting it. The function is parseInt()
Note, the capital 'I'. It's case sensitive. Check this link for the ins
and outs of it:
http://www.w3schools.com/jsref/jsref_parseInt.asp
alert("vat_low" + rowNum);
alert("vat_low" + rowNum.value);
<!-- alert (parseint(document.splitfm.vat_low.value)); -->
alert (newTxt2.ID)
the parseint bit halts the script.
can I use the ID ?
is there an ID .value?
If I do an alert for this it says Undefined?
You're going in the wrong direction with this stuff.
Let's go back to my block edited for error (and the suggestion by
Julian), and I'll explain what exactly it's doing.
1 var sum = 0;
2 var vat_low;
3 for( var i = 0; i <= rowNum; i++ ) {
4 vat_low = 'sum += parseInt( document.splitfm.vat_low' + i +
'.value )';
5 eval(vat_low);
6 }
7
All the magic is happening on line 4 and 5. Basically, we've got a loop
that goes around once for every table row you've added. On line 4, I'm
saving a string into the variable vat_low by concatenating a literal
string with the value in i with a second literal string. So, on the
first iteration, the value of vat_low is:
"sum += parseInt( document.splitfm.vat_low3.value )"
Then on line 5, that string is executed as if it were a line of
_javascript_.
So, just to break that line down: the "document.valt_low3.value" gets
the value from the input box as we wanted. Now, the problem there is
that it's treated as a string unless we specifically make it an
integer, so we pass it to the parseInt() function. This returns the
value of that input box as an integer. Then that value is added to the
variable 'sum' as was neatly explained by Julian.
So, the net result is to loop through each added row and to add the
value of the low_vat input box into a variable that after the loop can
be assigned wherever you'd like (I'm assuming
document.splitfm.low_vattot.value).
Hopefully that helps and doesn't just make everything worse for you.
Have a look at the site http://www.w3schools.com/jsref/
It's got a lot of good stuff on it and should help you out in your
endeavors. And for Firebug, have a look at breakpoints and how to use
them. You'll never use alert() to debug ever again once you get the
hang of it (http://www.getfirebug.com/js.html).
Thanks again for the help I will put aside some time tomorrow for the
above links
meanwhile.....
I have edited the loop but still get only the literal string "sum +=
parseInt( document.splitfm.vat_low3.value " as an input to the box
low_vattot
what do I need to convert this to the .value?
--
Regards:
Kevin Lucas
Post Master (Sub)
Minions Shop & Tea Rooms
Minions
Liskeard Cornwall
PL14 5LE
www.minionsbandb.co.uk
|