"Santosh" <go***********@rediffmail.com> wrote in message
news:1c************************@posting.google.com ...
Hi,
I have a requirement in which, I need to capture a loan amount and the
amount of down payment for that loan. According to the requirement,
the user is going to enter enter the loan amount and then will enter
the down payment in either percentage of the loan amount or an actual
amount. I have designed a form to capture this information with three
text fields, one each for loan amount, down payment in % and down
payment in $.
So the user has the option of entering downpayment in $ or in %. If
the user enter the down payment in $ then my code has to calculate the
equivalent % value and populate the corresponding text field and vice
versa. My question here is, what would be the best way to handle this
situation.
Shall i just use the OnChange event of the text field to handle this
scenario? If I do that wont I be running into a loop?
Thanks in Advance
-Santosh
Will this help? Watch for word-wrap.
<html>
<head>
<title>loan.htm</title>
<script type="text/javascript">
function calc(what) {
var form = document.form1;
var lamt = form.loan_amt.value;
var valu;
if (what == 0) {
valu = lamt / form.down_amt.value;
form.down_pct.value = valu;
} else {
valu = lamt * form.down_pct.value / 100;
form.down_amt.value = valu;
}
}
</script>
</head>
<body>
<p>
<form name="form1">
Loan Amount =
<input type="text" name="loan_amt" size="6" style="text-align:right">
<br>Down Payment Amount = <input type="text" name="down_amt" size="6"
style="text-align:right" onblur="calc(0)">
<br>Down Payment Percent = <input type="text" name="down_pct" size="6"
style="text-align:right" onblur="calc(1)">
<br><input type="button">
</form>
</body>
</html>
There is no data validation not formatting.