How can I set focus in a specific field in an html form?
I found one post that gave a way to do it if using an onload event handler, but I'm not using such a thing.
The form is a straightforward one generated by php with no java or javascript involved at all.
I would like the cursor to be in the first edit field when the form loads.
Set focus in a field?
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
searched for it at http://www.w3.org/MarkUp/ but found no property to do so.
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
Got the answer.
Got the answer from a javascript forum at http://www.webxpertz.net/forums
You use the body tag, the index of the form on the page, and the name of the input that you want to have the focus.
<body onload="document.forms[0].Password.focus()">
You use the body tag, the index of the form on the page, and the name of the input that you want to have the focus.
<body onload="document.forms[0].Password.focus()">
Use something like this..
..this is obviously JavaScript 
Hope this helps.
Code: Select all
function FocusMe(target)
{
window.form.target.focus(); //target is the name of the input field
}
// to call this function just send it the name of the input you want to focus
// this this... and it should work.
FocusMe('password');Hope this helps.