PDA

View Full Version : making form buttons perform multiple commands


schnitzel_ESC
12-21-2003, 07:01 PM
hi, i', trying to build a speed/rpm/reduction calculator, i have all the formulae, but i can't work out how to make all the formulae 'go' with the click of one button,

here is an example form that i come up with:

<form name="calc2">
A: <input type="text" name="A" size="10"> <br>
B: <input type="text" name="B" size="10"> <br>
<input type="button" name="add" value="="
onClick="document.calc2.C.value =
parseInt(document.calc2.B.value) +
parseInt(document.calc2.A.value)";
"document.calc2.D.value =
parseInt(document.calc2.B.value) -
parseInt(document.calc2.A.value)"> <br>
C: <input type="text" name="C" size="10"><br>
D: <input type="text" name="D" size="10">
</form>

i want to be able to click the button, and to have A+B in C, and A-B in D. Could you please edit this form, to make it work correctly. Thanks
Nigel:)

.::14 YEAR OLD::.

ucm
12-22-2003, 12:48 AM
sure; try this :)


<form name="calc2">
A: <input type="text" name="A" size="10"> <br>
B: <input type="text" name="B" size="10"> <br>
<input type="button" name="add" value="="
onClick="f = document.calc2;
aVal = parseInt(f.A.value);bVal = parseInt(f.B.value);
f.C.value = (aVal+bVal);f.D.value = (aVal-bVal);"> <br>
A+B=: <input type="text" name="C" size="10"><br>
A-B=: <input type="text" name="D" size="10">
</form>

schnitzel_ESC
12-22-2003, 07:03 PM
Thanks that helps lots. if you want to see what i'm working on, check geocities.com/the_21st_schnitzel in a week or so :)