Click to See Complete Forum and Search --> : totalling amounts input by user
I need a script that can total up the amounts entered in by a user. In other words they are asked to list their current loan amounts...and as they enter each amount I need a script that will add the amounts together and enter them into a separate "TOTAL" field. Is this possible?
Sceiron
12-10-2002, 12:30 PM
Perhaps something like this will get you going in the right direction...
<script type="text/javascript">
function calcTotal(that) {
thisTotal = 0;
for (i=1; i <= 5; i++) thisTotal += that.form.elements['num' + i].value - 0;
that.form.numTotal.value = thisTotal;
}
</script>
<input type="text" name="num1" value="" onblur="javascript:calcTotal(this);"><br>
<input type="text" name="num2" value="" onblur="javascript:calcTotal(this);"><br>
<input type="text" name="num3" value="" onblur="javascript:calcTotal(this);"><br>
<input type="text" name="num4" value="" onblur="javascript:calcTotal(this);"><br>
<input type="text" name="num5" value="" onblur="javascript:calcTotal(this);"><br>
<input type="text" name="numTotal" value="">
Zach Elfers
12-10-2002, 09:12 PM
Or you could do:
<script language="JavaScript">
function addTotal(form) {
if (form.add1.value) {
form.add1.value = form.add1.value + "1"; // Change the plus symbol to -, * (multiply), / (div.), % (modulus)
}
return true;
}
</script>
<form>
<input type="text" name="add1" onBlur="addTotal(this.form);">
</form>
The problem I'm having in trying to use these scripts is that my email reply script requires that I use [ ] around the name of the field. When I try to incorporate them the "adding" script doesn't want to work. If it would help ... one of the tables that I'm trying to use this for is at http://www.golocal.com/test/creditapp-test2.html . The numbers could total as they're entered or I put in a button for "total now" (which would probably be better)...either way is acceptable. I am not a script writer (as you can probably more than tell!) but I can usually fudge them enough to work...but this one's giving me fits! Thanks to everyone for their input!
Zach Elfers
12-11-2002, 09:39 PM
Do you mean like this? :
"[" + form.fieldName.value + "]"