PDA

View Full Version : Can't get focus() to work


dulciew
10-22-2002, 05:32 AM
I have this code that when the link is clicked, the text boxes are cleared and the cursor appears in the Amount textbox, but the focus won't focus and I don't know what the problem is. Can someone help. Thanks. PS I have all the breaks in because the form is supposed to be at another part of the page.

<HTML>
<HEAD>
<SCRIPT language="JavaScript">
function doMort( ) {
document.MortCalc.Amount.focus( )
document.MortCalc.Amount.value=" ";
document.MortCalc.Rate.value=" ";
document.MortCalc.Years.value=" ";
document.MortCalc.Payment.value=" ";
}
</SCRIPT>
</HEAD>

<BODY>


<DIV align=center><A href="#LoanCalc" onClick=doMort()>Estimate Mortgage Payment</A>
</DIV>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<A name=LoanCalc>
<H3 align=center>Estimate Mortgage Payments</H3>
<CENTER></A><BR>
<TABLE>
<FORM name=MortCalc>
<TBODY>
<TR>
<TD>Amount of Mortgage:</TD>
<TD><INPUT size=9 value=" " name=Amount></TD></TR>
<TR>
<TD>Interest Rate as % (e.g. 7.9):</TD>
<TD><INPUT size=9 value=" " name=Rate></TD></TR>
<TR>
<TD>Number of Years:</TD>
<TD><INPUT size=9 value=" " name=Years></TD></TR>
<TR>
<TD>Monthly Payment:</TD>
<TD><INPUT size=12 value=" " name=Payment></TD></TR>
<TR>
<TD><INPUT type=button value=Calculate> <INPUT type=reset value=Reset></TD></TR></TBODY></TABLE></FORM></CENTER>
<HR>
<BR><BR></BODY></HTML>:(

glenngv
10-22-2002, 06:04 AM
put the focus statement at the end of the function.

but why not just do a form reset then set focus on that element?

Coral_Lover
10-22-2002, 07:55 AM
Hi dulciew, why don't u change from ><A href="#LoanCalc" onClick=doMort()> to <A href="#" onClick=doMort()>?
I think the focus shd work when u click on the link. Try it.

glenngv
10-22-2002, 08:21 AM
you don't have the <form> tag, which I supposed to be named MortCalc as you coded in your doMort() function:

function doMort( ) {
document.MortCalc.Amount.focus( )
document.MortCalc.Amount.value=" ";
document.MortCalc.Rate.value=" ";
document.MortCalc.Years.value=" ";
document.MortCalc.Payment.value=" ";
}

put this tag:

<form name="MortCalc">

then in your doMort() function:

function doMort( ) {
document.MortCalc.Amount.value="";
document.MortCalc.Rate.value="";
document.MortCalc.Years.value="";
document.MortCalc.Payment.value="";
document.MortCalc.Amount.focus( );
}

dulciew
10-22-2002, 11:07 PM
I have tried putting the focus() at the end of the script and I do have a form name in my form. I have noticed that when I take the same page link out the focus() works fine.
Thanks for your help.