Buy Shares | Fast Loans | The eBay Song | Credit Card | Remortgages
Forms and adding [Archive] - ZGeek

PDA

View Full Version : Forms and adding


Pirate
21-07-2005, 12:27 PM
I making a form where you list dollar amounts. At the end of the form I'd like to have a box that adds the values from these input areas and totals it in the totals box.

Has anyone seen any scripts that can do this or point me in the right direction?

dwarfthrower
21-07-2005, 12:31 PM
It depends, have you got a fixed number of fields or is it variable?

Pirate
21-07-2005, 12:33 PM
s'cool. I figured it out with some java.

Reprobate
21-07-2005, 12:36 PM
s'cool. I figured it out with some java.
Give us the linky of where you found it.

It'd be interesting to see how it works.

dwarfthrower
21-07-2005, 12:38 PM
s'cool. I figured it out with some java.
No worries... coffee helps me think too ;)

btwong
21-07-2005, 02:49 PM
Give us the linky of where you found it.

It'd be interesting to see how it works.

i would assume it is just simple "onclick/onchange" etc event on each input boxes, that once a number is entered, it loops through all the input fields, adding them up in a variable, and then displays the vairable in a disabled input box for the toals, automatically using something like:

document.totalbox.value=allboxtotals;

where "allboxtotals" would be the addition of all the input boxes that allow the dollar values to be entered.

(i just thought i would answer it cause i am bored!)

Pirate
21-07-2005, 03:02 PM
its basically like btwong said.

I stole some code and reworked it.function csum()
{
var tsum=0;
for ( normalanswer1 = 1; normalanswer1 < 5; normalanswer1++ )
{
k = "normalanswer" + normalanswer1;
tsum += document.getElementById(k).value/1;
}
tsum = Math.floor((tsum + .005)*100)/100;
document.getElementById("s1").value = "$" + tsum;
}
Original code is here
http://webdeveloper.earthweb.com/webjs/jsform/item.php/681841