View Full Version : Calculated Field

08-12-2008, 10:25 PM
I have a form with 3 fields:

Purchase Price: <input type="text" name="purchasePrice" size="10">

Sale Price: <input type="text" name="salePrice" size="10">

Profit: <input type="text" name="profit" size="10">

I'd like the profit field to be automatically filled in once the salePrice field loses focus.

Any help on this would be greatly appreciated.

08-12-2008, 10:53 PM
This will do it

function profit(){
pp = document.form[0].purchasePrice.value;
sp = document.form[0].salePrice.value;
profit = pp - sp;
document.form[0].profit.value = profit;