View Full Version : Need to create a form that calculates 3 fields...

01-26-2006, 11:16 PM
I want to have two fields. You put in a number (ie 10) then in the next field you put another number (ie 15) then it multiplies those numbers together, and then mulitplies the result by .75

anything out there already? or something that can be modified? i'm not a JS expert, so some assistance might be needed if we can find something that will work..'


01-26-2006, 11:54 PM
javascript will allways try to convert strings to numbers when multiplying and dividing.
so in this case you can just say:
Result = field1.value * field2.value * .75;

whereas if you want to add or substract,
you will have to convert the strings to numbers before the calculation.
It can be done by multiplying the strings by 1 .e.g.:
Result = (field1.value * 1) + (field2.value * 1);.

need more help? just ask!

01-27-2006, 06:44 AM
Thanks, but i'm a total noob at JS... I can't really figure it out by the line of code you gave...

Could you use it in an example form?

Thanks a million!! :)

01-27-2006, 07:23 AM
Okay, nevermind. I figured it out!! Thanks!!

01-27-2006, 07:25 AM
<script language="javascript">

function doMath(valueA, valueB, multiplier){
return (valueA*valueB*multiplier);


<form onsubmit="alert(doMath(this.boxA.value, this.boxB.value, .75));">
<input type="text" name="boxA"><br>
<input type="text" name="boxB"><br>
<input type="submit">

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum