View Full Version : Form/dropdowns that calculate total into a textarea?

02-05-2004, 09:57 AM

I've got a form with many dropdown boxes - what needs to happen is people select things in the dropdown boxes and a number is calculated at the bottom. Each dropdown box might have something like:

Type of user: * Newbie (1 point)
* Regular (5 points)
* Addict (10 points)

Donation: * $0-$5 (add 10 points)
* $5-$10 (add 20 points)
* $10-$20 (add 25 points)

Time on forum: * 1 week (multiply by 1)
* 1 month (multiply by 2)
* 6 months (multiply by 3)
* 1 year (multiply by 4)

At the bottom of the form there is a "Calculate" button, and a textarea called "total points". What I want to happen is for a number to be calculated when they click on the button, depending on what was chosen in the dropdown box - and the total value comes up in the textarea.

(If it's possible, the button doesn't even need to be there - maybe anytime something is selected in the dropdown box, the total is automatically calculated?)

I'm not sure how I calculate this, or give each dropdown box entry its own value. I realize I can do this in PHP, but it's important that it all happens on the one page.


Willy Duitt
02-05-2004, 10:26 AM
You can find examples of math operators here (http://www.paschools.pa.sk.ca/javascript/math.htm).


02-05-2004, 10:42 AM
Put the corresponding point in the option value so that you'll know how many points is associated to an option.

<select name="userType" onchange="calculate()">
<option value="1">Newbie</option>
<option value="5">Regular</option>
<option value="10">Addict</option>

And use onchange event handler to do the calculation.
Try to do the code on your own and post back here if you encountered any problem.

Willy Duitt
02-05-2004, 11:13 AM
Don't forget to check your other thread (http://www.webxpertz.net/forums/showthread.php3?s=&threadid=27584) for replies.