Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Form/dropdowns that calculate total into a textarea?

    Howdy,

    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.

    Thanks!

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can find examples of math operators here.

    .....Willy

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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>
    </select>

    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.

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't forget to check your other thread for replies.

    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •