Forum Moderators: open

Message Too Old, No Replies

Is it worthwhile selecting a form element onLoad

or is it harmful?

         

korkus2000

2:48 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yahoo started selecting their search box a while back when the page finishes loading. I have Yahoo as my start page and this has really made me angry. I will try and type in a URL but it ends up in Yahoo's search box. It has annoyed me to the point of changing my start page. It may help them get some more contract searches with their third party search provider, but it doesn't help me at all.

When I develop form pages it has always been a good thing to select form elements, or at least I thought. Every web programmer I code with thinks a focus on the first element helps usability. I am starting to disagree with that.

One site I go to frequently has a login on their homepage. I do login, but the problem is I am on the password field when the page finish loading and half of my password is in the username field. This is always irritating so I wait for the page to completely load. This couple of seconds on DSL really makes me angry, but if I start too quickly I lose more than a few seconds.

So what do others think? I am done adding form focus onLoad. I will only use that during validation. I really have to thank Yahoo for forcing me to see the annoyance.

BlobFisk

3:04 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree with you korkus. I think that there is no usability benefit to be got from a form focus onLoad - in fact I would go as far as to say that it can be confusing and more hassle than benefit to the user.

I believe simply in giving the user full control over my pages... be it using relative widths, to not using onLoad field focuses.

It can be hard to resist the temptation of using every DOM manipulation under the sun, and spoon feeding the user completely. I feel that this can be stifling for them - lots of control and lots of whitespace!

macrost

3:16 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



Korkus,
I heartily agree. I will only use that onFocus on a page that is just a login page.
Mac

dingman

3:40 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have exactly one page where I use Javascript to focus a form element, and I added it because one of my users suggested it. She's probably my best user for feedback, and usually everyone likes it when I implement the things she suggests. It's now been up for at least a few months, and people seem to like the change. However, it's a page that has litterally nothing on it other than a login form, and in most cases I agree that focusing a form is not so useful.

To get around the annoyance of having a field focused when you're halfway through loging in, I avoided the onLoad event. Instead, I used a <script> section right after the form, so that it gets run as soon as the document elements it referrs to have been created, rather than waiting for the whole page to load. It seems to work. I also test to see if the username field has a value, and if it does I focus password instead.

Is there a way to get the default value of a field in javascript rather than the current one? If so, I could make that script even less likely to be annoying.

korkus2000

3:44 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Depends on the element, but for a textbox you can use defaultValue instead of value. I am not really sure about support. If you do write a less annoying script please share it.

RonPK

4:54 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My opinion: focussing is very useful whenever entering data into the form field is the primary thing to do on the page. I.e. a search engine or a logon page.

Focussing makes it impossible to scroll down using the keyboard arrows, which is very annoying whenever receiving data is not the primary purpose of the page. For example some company's home page: it's very nice if there is a site search option, but please don't focus and let me scroll...

dingman

5:17 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script type="text/javascript"> 
if (document.forms.loginform.username.value == '')
{
document.forms.loginform.username.focus();
}
else if (document.forms.loginform.username.value ==
document.forms.loginform.username.defaultValue)
{
document.forms.loginform.password.focus();
}
</script>

This should focus the username field if it is empty, and the password field if the username is filled in, but still the default value, and otherwise do nothing. I've only tested it in Gecko so far, 'cause that's what I have handy. I'll try it in a few others when I get home this evening.

The idea is that the form in question may be generated with or without the username field pre-filled, depending on whether I have a good guess about who is trying to log in. (Usually from a GET variable.) If the username field is empty, then that's where we want to start, since there's nothing else on the page, not even a link. If the username field is not empty, that could either be the result of user input or a default value in the form. If it's a default value in the form, then along with guessing that we know who is about to log in, we want to put the cursor in the password field instead of the username field. (Focusing the password field when the user is already typing there should be harmless, right? The page loads too fast for me to test this theory, but if not then there should also be a test to see if the password field has been changed.) If the username has been changed in any way from what we initially sent, though, we don't want to steal the cursor from wherever the user is typing now, so we do nothing.

<edit>fixed side scroll, corrected two mis-statements.</edit>

[edited by: dingman at 5:20 pm (utc) on June 23, 2003]

pixel_juice

5:20 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



I find form focussing (especially on search engines) to be really useful. I've come across the same half-typing problems as korkus2000, however, if I'm browsing with just a keyboard (which I do too often ;)) then it saves me a lot of time tabbing around the place.