Adding the values in text boxes

F

Frank

I have a large form, that has text boxes of numbers in rows and
columns. I need to sum the values in the columns, and put the total at
the bottom of the column. But I also need to sum the values in each
row, and put the total at the end of the row.

What is the javascript to sum the values to a few text boxes, and how
would I write the script for these totals to run all at once?

Thanks.
 
E

Erwin Moller

Frank said:
I have a large form, that has text boxes of numbers in rows and
columns. I need to sum the values in the columns, and put the total at
the bottom of the column. But I also need to sum the values in each
row, and put the total at the end of the row.

What is the javascript to sum the values to a few text boxes, and how
would I write the script for these totals to run all at once?

Thanks.

Hi Frank,

It is not complicated at all.
You must just give every field a clear name and use some basic javascript to
do the adding.

for example:
your fields have the following names:
row1col1 row1col2 row1col3 row1col4 row1total
row2col1 row2col2 row2col3 row2col4 row2total
row3col1 row3col2 row3col3 row3col4 row3total
totalcol1 totalcol2 totalcol3 totalcol4

<script type="text/javascript">
var numrows = 3;
var numcols = 4;

function dototalrows(){
for (var row=1; row=<numrows; row++) {
var totalrow = 0;
for (var col=1; col=<numcols; col++) {
totalrow += document.forms["yourformname"]["row"+row+"col"+col].value;
}
document.forms["yourformname"]["row"+row+"total"].value = totalrow;
}
}
</script>

do the same for cols.
(I didn't check my code, so forgive me any typos.)

Maybe add some errorchecking for invalid values.

Good luck!
reagrds,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top