Click to See Complete Forum and Search --> : Simple Math?

04-11-2002, 09:38 AM
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 = $_______


04-11-2002, 01:14 PM
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.

04-11-2002, 02:18 PM
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!

04-11-2002, 02:20 PM
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 will wind up as a string, "1.393.46"
just explicitly convert to a number:


04-11-2002, 07:00 PM
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]

04-11-2002, 08:13 PM

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

04-12-2002, 08:42 AM
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]