Jump to content

Set focus on form (not input control)

Recommended Posts

I know how to set focus on a specific input control, e.g. a text box, e.g.:
     <script type="text/javascript">
Now I have a web page with no input controls. The problem is that Page Down doesn't work until I click somewhere on the form to have it receive focus.
I would like that to happen automatically when the page loads, but I haven't found a solution.

The page contains two forms with tables inside. I have tried to use focus() on the form or on a (disabled) input control, but nothing works.

Can anybody help me? Thanks in advance...

Share this post

Link to post
Share on other sites

There's a discussion here about elements and focus:


Maybe try to put a tabindex on the form, or else you need to set up an element that can receive focus, like an anchor.  Or, if you have a custom keypress handler for page down, maybe you need to change how that's set up.

Share this post

Link to post
Share on other sites

Thanks. Unfortunately I can't get setfocus() to work (in Chrome) on anchors or elements with tabindex. However, I succeeded in getting it to work with a readonly input element in one case and am still experimenting with other cases.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...