Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onload focus not working ?

Status
Not open for further replies.
Feb 7, 2002
11
GB
Hi,

I've got a perl script which is embedding a javascript snippet to (try) focus on a form element.

It looks like this :


<BODY onload=&quot;document.002_3A.description.focus();&quot;>

The rest of the HMTL has multiple forms :

<TR><TD ><IMG SRC='/Photos/Dee Gliding/th_001_2A.JPG'></TD>
<FORM METHOD='post' NAME='001_2A' ACTION='manage.pl?table=dee_gliding'>
<INPUT TYPE='hidden' name='action' value='update'>
<INPUT TYPE='hidden' name='table' value='dee_gliding'>
<INPUT TYPE='hidden' name='filename' value='001_2A.JPG'>
<TD>001_2A.JPG</TD><TD>
<INPUT TYPE='submit' NAME='show' VALUE='Hide'></TD><TD><INPUT TYPE='text' name='description' size='50' value='Sunset over Camberley Avenue' onUnfocus=&quot;send()&quot;></TD>
</FORM></TR>

<TR><TD ><IMG SRC='/Photos/Dee Gliding/th_002_3A.JPG'></TD>
<FORM METHOD='post' NAME='002_3A' ACTION='manage.pl?table=dee_gliding'>
<INPUT TYPE='hidden' name='action' value='update'>
<INPUT TYPE='hidden' name='table' value='dee_gliding'>
<INPUT TYPE='hidden' name='filename' value='002_3A.JPG'>
<TD>002_3A.JPG</TD><TD><INPUT TYPE='submit' NAME='show' VALUE='Hide'></TD><TD>
<INPUT TYPE='text' name='description' size='50' value='Sunset over the rugby club trees' onUnfocus=&quot;send()&quot;></TD>
</FORM></TR>


I was intending the focus to go to the second form above, to the description text-box, but this doesn't happen.

I've tried saving the output of the script to a .html file and accessing that directly to take the CGI side out of the equation, but the result is indentical.

Hope someone can help :)



 
You cannot reference forms or elements with names that start with numbers with Javascript. Same rule as variable naming.
 
You MIGHT be able to use:

document.forms['002_3A'].description.focus()

but I'm not sure. It's still not a good idea to start form or element names with digits because of JS referencing problems.
 
Thanks !!

I got the script to spit out ascending numeric characters as an ID , and it works nicely now!

While I'm asking, is there any way to centre the page around the focus ?

Thanks again for the help !
 
If the length of the page allows, the focused element will be at the top of the page. If not, the page will be scrolled up as far as possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top