View Full Version : Focus won't work

05-05-2005, 09:18 PM
The focus statement, right below the ??? comment will not work. What am I doing wrong ?? Thanks

<title>Mortgage Calculator</title>

h1 {color:black; font-family:Arial; text-align:center; }

table {color:black; font-family:Arial; font-size:18;}



function Monthly(I, N, S) {
return (S*I/12*Math.pow(I/12+1,N))/(Math.pow(I/12+1,N)-1);
} // end function Monthly(I, N, S)

function ShowVal() {

var SS = eval(document.mortgage_form.LoanAmount.value);
/* alert("SS =" + SS); */

var NN = eval(document.mortgage_form.TotalNumberMonths.value);
/* alert("NN =" + NN); */

var II = eval(document.mortgage_form.YearlyInterestRate.value);
/* alert("II =" + II); */

var TP = Monthly(II, NN, SS);

document.mortgage_form.MonthlyPayment.value = TP;

document.mortgage_form.TotalOfPayments.value = TP * NN;

} // end function ShowVal()

function CheckInterest() {
var Int = eval(document.mortgage_form.YearlyInterestRate.value);
/* alert("CheckInterest Int =" + Int); */

if(Int <= 0 || Int >= 1) {

alert("Fix the interest, you fool");

document.mortgage_form.YearlyInterestRate.value = "";

/* ?????? */

} // end if

} // end function CheckInterest()



<h1> Mortgage Calculator</h1>

<table width="60%" align="center">
Enter the yearly interest rate as a decimal, the total number of monthly payments,
and the amount of the mortgage.
Click the Calculate button to view the monthly payment.
Click the Reset button to reset the form.

<form name="mortgage_form"><center>
<td>Loan Amount</td>
<td><input class="number" name="LoanAmount" size="15" maxlength="15" value="">

<td>Yearly Interest Rate</td>
<td><input class="number" name="YearlyInterestRate" size="15" maxlength="15" value="" onchange="CheckInterest()"></td>

<td>Total Number of Months</td>
<td><input class="number" name="TotalNumberMonths" size="15" maxlength="15" value=""></td>

<td> <input type="button" value="Calculate" onclick="ShowVal()"></td>

<td> <input type="reset" value="Reset"></td>
<td>Monthly Payment</td>
<td><input class="number" name="MonthlyPayment" size="15" maxlength="15" value="" disabled></td>

<td>Total of Payments</td>
<td><input class="number" name="TotalOfPayments" size="15" maxlength="15" value="" disabled></td>




05-06-2005, 09:32 AM
Don't ask me why but, use onBlur instead of onchange here:

<td><input class="number" name="YearlyInterestRate" size="15" maxlength="15" value="" onBlur="CheckInterest()"></td>Only thing I can figure is, onchange occurs while focus is still on the element.

05-06-2005, 10:01 AM
I was so pleased with myself for getting that to work, I neglected to test it in Mozilla, it works in IE but not in NS7.2

This works in both:

setTimeout("document.mortgage_form.YearlyInterestRate.focus()",20);Substitute that for your dis-functional line. Using this code, it makes no difference if onBlur or onChange is used in the HTML section.

05-06-2005, 01:28 PM