View Full Version : calculate within form AND send the input

08-22-2002, 05:21 PM
I use a form in which I i have 3 inputfields. The third field is filled in by pressing a button which calculates the value, based on the input of value 1 and 2.

- input 1 <input ...>
- input 2
- input 3 for ex. = value input 1 / input 2 + 150
press button to calculate
- sent

However, when i make the calculation, nothing is sent anymore. Whet can i do to keep the values as input, but still make a
calculation. I want to send all 3 the values.


08-22-2002, 05:40 PM
Maybe this?
function calcAndSend(f) {
var v1 = parseInt(f.elements['val1'].value);
var v2 = parseInt(f.elements['val2'].value);
var answer = v1/v2 +150;
f.elements['solution'].value = answer;
return true;


<form onSubmit="return calcAndSend(this)">
Value 1<input type="text" id="val1" name="val1" /><br/>
Value 2<input type="text" id="val1" name="val1" /><br/>
<input type="hidden" name="solution" id="solution" />
<input type="submit" value="Send Data" />