[Javascript] Re: Updating a text box - calculations

Matthew Palmer mpalmer at hezmatt.org
Tue Feb 1 19:47:04 CST 2005


On Wed, Feb 02, 2005 at 11:33:41AM +1030, Tim Burgan wrote:
> In a form, I have 5 text boxes vertically on top of each other. Each 
> where the user can enter a dollar amount.
> 
> Then in a 6th text box.. it displays 2% of the sum of the 5 text boxes.
> 
> Then a 7th text box adds the values of all 6 text boxes to give a grand 
> total.
> 
> How in the world do I do this with Javascript?

Easy.  Write a function that makes the appropriate calculations from the
first 5 boxes and sets those values into the 6th and 7th, and then make
onChange or onBlur trigger that function.

> Are there any resources available anywhere that describe how to do 
> something like this?

Probably about a million of them on the web, but see
http://www.computertown.com.au/package_deals/basic/quote/parts_frame.htm for
an example of this kind of thing (although far more complex than what you're
trying to do).  Note that only the JS is mine -- the hideous design is
someone else's fault.  <grin>

- Matt

-- 
"This is my rifle. This is my gnu. This is for killing. This is for $foo."
		-- AJS, in the Monastery
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050202/5b7e3f80/attachment.pgp>


More information about the Javascript mailing list