Javascript for making form fields multiply & add up

Discussion in 'JavaScript' started by taracakes, Apr 15, 2010.

  1. #1
    Hi!

    I've created a form using html and asp that is an order form that is emailed.

    I am looking to insert formulas into the text areas of the form- similar to an excel sheet... Basically the form should look like this...

    Part Number Description Quantity Cost Amount
    74897389 First Item 4 $5 $20
    43274387 Second Item 2 $6 $12
    Total: $32

    So basically I need two types of formulas... One that will multiple the quantity and the cost- and put that number in the "amount" cell for that product. The other formula will add up the last row (all of the amounts) and put that final figure in a "total" field.

    Then once these fields are automatically filled in, and the user has completely the form, the Submit button will include these calculations in the email as well.

    I use 3dcart which does not support PHP.

    I've done a lot of searches for this, but I'm not finding the answer!

    Any help would be MUCH appreciated!!!
     
    taracakes, Apr 15, 2010 IP
  2. taracakes

    taracakes Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is this a stupid question? Because a lot of people have viewed it but not responded... Even just some hints would great!
     
    taracakes, Apr 15, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't realy understand your question. But this is what I would do for javascript.

    put this in an onchange function on each of the fields

    javascript:
    
    //gets values of field 1 and 2
    f1 = document.getElementById('field1').value;
    q1 = document.getElementById('quantity1').value;
    f2 = document.getElementById('field1').value;
    q2 = document.getElementById('quantity2').value;
    if(f1 != null && f2 != null)
    {
    //does math on the values of field 1 and 2
      f1 = f1*q1;
      f2 = f2*q2;
      od = f1 + f2;
    //makes the value of outputfield = field1 + field2
      document.getElementById('outputfield').value = od;
    }
    
    Code (markup):
    I'm not sure if this is what you want. If it isn't please explain your question better.
     
    Imozeb, Apr 15, 2010 IP
  4. parshwanath

    parshwanath Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can anybody explain how to calculate total amount in html form?

    I want to calculate and process while the visitor clicks check out. And the calculation is like to multiply and add to the amount.

    For eg., a visitor has enter amount as 10 and I need to multiply it with 25 and add 20% to the value and which click checkout, it should be 300. So how can I get that in a html form?
     
    parshwanath, Sep 23, 2010 IP