Web Analytics Made Easy -
StatCounter Adding Form Fields Together (Having Real Problems!) - CodingForum


No announcement yet.

Adding Form Fields Together (Having Real Problems!)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding Form Fields Together (Having Real Problems!)

    I am currently working on a page for a friend who is wanting to give users the option of choosing the number of tickets they want and then the form calculating how much it costs for those tickets and then totals it at the bottom

    I'm really struggling with the JavaScript. I have coded something already (code is within the attached txt file as it was too long to post) but I am having lots of trouble getting the tickettotal field at the end to total all the fields above it. Basically, it doesn't seem to add them together at all - I just get an error displayed in it saying undefined and then the other field values after undefined. If I remove the curr_format function it accepts the values of the fields but instead of adding them together it just puts them all in side by side (for instance, if the two field values were 10 and 20 it puts in the total 1020 instead of what I want which is 30 - 30.00 is what I'm aiming for)

    Can anyone offer me any suggestions/pointers on what I am doing wrong - pointing me in the right direction (or just a sample) rather than coding it all is what I want so that I can learn from other's and also my own mistakes

    Thanks for any help

  • #2
    If it's concatenating numbers like strings instead of performing math operations just use the "number" function to force numeric operations.

    result = number(variable1) + number(variable2);
    Check out the Forum Search. It's the short path to getting great results from this forum.


    • #3
      Thanks for your suggestion Roy

      I've now managed to sort this out using parseFloat and altering my code slightly