PDA

View Full Version : Local forms


Grayman
03-26-2001, 03:42 PM
This is my first post on this forum.

I want to write a daybook for a club I belong to.
I have designed the page, with dropdowns for member name etc., but some of the columns have numeric entry which need totalling, and the result placed at the bottom of the column. I have no idea how to do it (if it can be done)and I will need to print the whole thing at the end of the day (that seems to work fine).
Anyone out there got any ideas ??

G

kdjoergensen
03-27-2001, 03:43 PM
var total = 0;
for (var j=0;j<document.formName.elements.length;j++){
if (document.formName.elements[j].type == "text"){
total += parseFloat(document.formName.elements[j].value);
}
}
alert(total);

Above will loop through all elements in a form with the name: formName. if the element is of the type "text" it will add the entry to the variable named total.
If you have input elements of the type "text" which does not contain numbers then nothing will be added. parseFloat will take care of that.

Kenneth