[Techtalk] html and focus
Kai MacTane
kmactane at gothpunk.com
Thu Nov 9 18:01:33 UTC 2006
At 07:00 AM 11/9/2006, Robyn M wrote:
>I'm trying to work out how to get the first input box to have the focus
>when I open a page with a form.
Simplest way? Do like this:
<body onload="document.getElementById('some_id').focus();">
... stuff including opening <form> tag ...
<input type="text" name="whatever" id="some_id">
In the <input> tag, you can certainly have "whatever" and "some_id"
be the same; I just wanted to highlight the fact that having the
<input>'s id attribute match the argument to the getElementById()
call in the <body> onload event is the real key to making this work.
Naturally, this assumes the user has JavaScript turned on; I'm not
sure there's any way to do this without JS.
--Kai MacTane
----------------------------------------------------------------------
"And when I squinted/The world seemed rose-tinted;
Angels appeared to descend..."
--Depeche Mode,
"Waiting for the Night"
More information about the Techtalk
mailing list