A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Simple Math?

  1. #1
    Senior Member
    Join Date
    Mar 2001
    Posts
    124

    Arrow

    Could someone please supply me with a javascript function or some code for this problem? I want people to fill out the first 2 blanks and have javascript calculate the 2 totals (one which is in a dollar amount). Please help.


    _____ + ______ = _______ * .50 = $_______

    Thanks-

  2. #2
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    Just have a couple of input text boxes with say one variable of input1 and the other of input2.
    Then if you want to display the subtotal, just create a dynamic text box with a variable of lets say total then just
    total = input1 + input 2
    Then make another dynamic text box with a variable of final
    Then just:
    final = total *.5

    That should work. If someone sees any probs with my script go ahead and tell me that I'm wrong, I often am.

    But, if it works for ya, then all the better.

  3. #3
    Senior Member
    Join Date
    Mar 2001
    Posts
    124
    That sounds perfect. I don't know what I'm doing wrong with my script but it's not working right. Would you be able to show me how it would look in the code?
    Thanks a million!

  4. #4
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    nothing wrong with the math, but one thing about text boxes. they return a variable of type "string".
    so if you have input1 as 1.39 and input2 as 3.46 and say
    total=input1+input2;
    total will wind up as a string, "1.393.46"
    yuk!
    just explicitly convert to a number:

    total=number(input1)+number(input2);

  5. #5
    Senior Member
    Join Date
    Mar 2001
    Posts
    124
    Yea, I'll have a note to enter only numbers rounded up to the nearest inch, like:
    input1 + input2 = Total x .50= $Total


    The final total needs to be a dollar amount.

    If I code see what the whole code looks like, that would be great.
    [Edited by JDzines on 04-11-2002 at 07:02 PM]

  6. #6
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    total=number(input1)+number(input2);
    final=total*.5;
    final=Math.round(final*100)/100;

    this last line will round it to 2 digits.
    for example, if final is 56.7891
    final*100=5678.91
    rounded=5679
    divided by 100=56.79

  7. #7
    Senior Member
    Join Date
    Mar 2001
    Posts
    124
    That's about what I have, is this a Javascript form function, because I have it as a form and it's not working.
    I guess I don't know what the heck I'm doing when it comes to javascript. (I'll start studying)
    Thanks for your input-
    [Edited by JDzines on 04-12-2002 at 05:19 PM]

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center