I desired to have live calcualted fields in a form.

A thread "live field calculations" was much handy and I made the chages I required.

But I was not successful in adding one more condition for reverse calcualtion.

The page code given bleow is self explanatory.

Can anyone kindly help me.

Thanks to you all great guys.

===============================================

<html>
<head>Admin Page</head>
</body>

<div>

<form action="admin-page.php" method="post" name="myform" id="myform">
<div align="center">
<table width="757" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td>&nbsp;</td>
<td><div align="center">Contract</div></td>
<td><div align="center">Trade</div></td>
<td><div align="center">Entry Date</div></td>
<td><div align="center">Entry Rate</div></td>
<td><div align="center">Exit Date</div></td>
<td><div align="center">Exit Rate</div></td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">
<select name="contract" id="contract" size="1" class="textarea">
<option>JAN</option>
<option>FEB</option>
<option>MAR</option>
<option>APR</option>
<option>MAY</option>
<option>JUN</option>
<option>JUL</option>
<option>AUG</option>
<option>SEP</option>
<option>OCT</option>
<option>NOV</option>
<option>DEC</option>
</select>
</div></td>
<td><div align="center">
<select name="trade" id="trade" size="1" class="textarea">
<option>BOUGHT</option>
<option>SOLD</option>
</select>
</div></td>
<td><div align="center">
<input name="entry_date" type="text" id="entry_date" class="textarea">
</div></td>
<td><div align="center">
<input name="entry_rate" type="text" id="entry_rate" class="textarea">
</div></td>
<td><div align="center">
<input name="exit_date" type="text" id="exit_date" class="textarea">
</div></td>
<td><div align="center">
<input name="exit_rate" type="text" id="exit_rate" class="textarea">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">Capital</div></td>
<td><div align="center">Lot</div></td>
<td><div align="center">Points</div></td>
<td><div align="center">Profits/Loss</div></td>
<td><div align="center">Percentage</div></td>
<td><div align="center">Trade Cost</div></td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">
<input name="capital" type="text" id="capital" class="textarea">
</div></td>
<td><div align="center">
<input name="lot" type="text" id="lot" class="textarea" value="50" onFocus="this.value=''">
</div></td>
<td><div align="center">
<input name="points" type="text" id="points" class="textarea">
</div></td>
<td><div align="center">
<input name="profit_loss" type="text" id="profit_loss" class="textarea">
</div></td>
<td><div align="center">
<input name="percentage" type="text" id="percentage" class="textarea">
</div></td>
<td><div align="center">
<input name="trade_cost" type="text" id="trade_cost" class="textarea">
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="6"><div align="center">
<input name="doSave" type="submit" id="doSave" value="Save">
</div></td>
<td>&nbsp;</td>
</tr>
</table>
</div>
</form></div>
<script type="text/javascript">
function addEvent(els, type, func) {
if(!(els instanceof Array)) els = [els];
for(var i=0, n=els.length; i<n; ++i) {
if(els[i].addEventListener) els[i].addEventListener(type, func, false);
else els[i].attachEvent("on"+type, func);
}
}

String.prototype.trim = function() {
return this.replace(/^\s+/, "").replace(/\s+$/, "");
};
var trade = document.getElementById("trade");
var lot = document.getElementById("lot");
var capital = document.getElementById("capital");
var entry_rate = document.getElementById("entry_rate");
var exit_rate = document.getElementById("exit_rate");
var points = document.getElementById("points");
var profit_loss = document.getElementById("profit_loss");
var percentage = document.getElementById("percentage");
var trade_cost = document.getElementById("trade_cost");

addEvent(
[trade, entry_rate, exit_rate],
"keyup",
function(e) {
var vtrade = trade.value.trim();
var ventry_rate = entry_rate.value.trim();
var vexit_rate = exit_rate.value.trim()
var vlot = lot.value.trim()
var vcapital = capital.value.trim()
var nentry_rate = ventry_rate*1;
var nexit_rate = vexit_rate*1;
if(ventry_rate=="" || vexit_rate=="" || isNaN(nentry_rate) || isNaN(nexit_rate)) {
points.value = percentage.value = "";
return;
}

if (vtrade.value = "SOLD") {
(points.value = nentry_rate - nexit_rate);
}
if (vtrade.value = "BOUGHT") {
(points.value = nexit_rate - nentry_rate);
}
capital.value = (nentry_rate * vlot) * 25 / 100;
profit_loss.value = (points.value) * vlot;
percentage.value = (profit_loss.value) * 100 / vcapital;
trade_cost.value = (((nentry_rate * vlot) * 0.00004) + 9.9324) + (((nexit_rate * vlot) * 0.00004) + ((nexit_rate * vlot) * 0.00017) + 9.9324);
}
);
</script>
</body>
</html>
============================================