B
Bruno
How do you set the focus on a certain text field so that as soon as the page
loads up that particular text input box is in focus?
loads up that particular text input box is in focus?
Bruno said:How do you set the focus on a certain text field so that as soon as the page
loads up that particular text input box is in focus?
GD said:With Javascript.
...
<script type="text/javascript">
onload=function() {
document.tree.apple.focus()
}
</script>...
Bruno said:How do you set the focus on a certain text field so that as soon as the page
loads up that particular text input box is in focus?
Won't it already be there before you start typing though? I've visited
pages where I start typing but the cursor isn't in a box and it drives
me nuts.
Bruno said:How do you set the focus on a certain text field so that as soon as the page
loads up that particular text input box is in focus?
Paul Furman said:What else would you want to do? alt keys still work for menu tasks.
I don't see the problem. The script loads when the page loads so when
the page loads, your cursor is in the first box. A tab would move to the
second box, a mouse click would go to wherever you clicked unless you
can tab or click faster than java can calculate. I can understand a
larger page with multiple forms if you moved someone to an unexpected
box at the bottom. I don't use tab on web pages unless I'm in a form, I
see now that one tab takes me to the address bar, is this what you are
talking about? When I go to a page with a form, I expect to be able to
start typing and it annoys me to have to move my mouse (after wasting
time typing into nothingness) or tab twice. This seems common sense but
maybe I'm missing something.
GD said:Bruno said:How do you set the focus on a certain text field so that as soon as the page
loads up that particular text input box is in focus?
With Javascript.
If the form name is 'tree' and the element name is 'apple' then in the
HEAD element of your page add:
<script type="text/javascript">
onload=function() {
document.tree.apple.focus()
}
</script>
There are other ways to target form elements. This would target the first
element in the first form on your page:
document.forms[0].elements[0].focus()
This is a shortcut version of the above:
document.forms[0][0].focus()
See above. This being a newsgroup on HTML, I was looking for an HTML methodSearch Google for a tutorial about Javascript and DOM!
Paul said:What else would you want to do? alt keys still work for menu tasks.
I don't see the problem. The script loads when the page loads so when
the page loads, your cursor is in the first box.
I don't use tab on web pages unless I'm in a form, I
see now that one tab takes me to the address bar, is this what you are
talking about?
Bruno said:I was aware of a javascript method, just wondered if it was
possible in HTML.
Bruno said:How do you set the focus on a certain text field so that as soon as
the page loads up that particular text input box is in focus?
<BODY onLoad="document.forms.mail.subject.focus()">
It worked just fine, I guess it wouldn't if the visitor had java script
turned off. Have I done something wrong? Any harm in this?
OK I understand now that on a complex page with other links and
navigation, it will mess some people up (not many though <g>) but on a
simple form page, it makes sense to me and is what most people expect.
OK I understand now that on a complex page with other links and
navigation, it will mess some people up (not many though <g>) but on a
simple form page, it makes sense to me and is what most people expect.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.