Log in

View Full Version : Help with Set focus anyone?



Dance10Looks10
09-27-2005, 04:01 PM
I already have code that will set focus on a FORM statement from Twey - ONLOAD="document.forms[0].elements[0].focus()" - but between the BODY statement and where I want the focus, there are two separate tables and a .GIF. This makes the set focus fail every time.

Anyone have any suggestions?

Twey
09-27-2005, 05:00 PM
Give the element an id.
<input type="whatever" id="firstfocus"/>... then use
onload="document.getElementById('firstfocus').focus();"

However, the only thing that ought to mess up that script is if there is another form before that one, or if the first element can't receive focus (E.G. input type="hidden").

Dance10Looks10
10-01-2005, 03:46 PM
Thanks for the help, Twey. I've not run across this one before, that I know of.

The screeen does indeed put the focus where I want it, but it also puts the ONLOAD code on the screen as well. Very strange to me.

It appears you can't' slap an image in here but here's the code line:
<BODY SCROLL="no" CLASS="Margin4pct WhiteLeather" ONLOAD="document.getElementById('addressName').focus();">

the actual focus field looks like this:
<DIV CLASS="SectionTitle">
NAME AND ADDRESS
</DIV>
<LABEL FOR="addressName" CLASS="appointmentTD">
onload="document.getElementById('firstfocus').focus();"
Name:
<INPUT CLASS="appointmentInput" TYPE="text" ID="addressName"
TABINDEX="1" SIZE="18" MAXLENGTH="60" NAME="addressName"
ONBLUR="changeback(addressName)"
ONFOCUS="highlight(addressName)"
ONKEYPRESS="return handleEnter(this,event)"> </LABEL>

While it does set focus on thie field, the onload code appears as well. It preceeds the input field addressName. Any suggestions?

Thanks for al of your help, Twey. It is greatly appreciated! Bits and pieces of memory are returning but not all. The Medico's say I may never get everything back. Very frustrating for me.

jim ;)

Twey
10-01-2005, 04:41 PM
<LABEL FOR="addressName" CLASS="appointmentTD">
onload="document.getElementById('firstfocus').focus();"
I'm not surprised :) You've forgotten to remove that code, just closing the tag before it so the browser sees it as text. Remove the red text.

Dance10Looks10
10-01-2005, 06:05 PM
Right as rain just like always. Thanks! :)