/    Sign up×
Community /Pin to ProfileBookmark

set focus on first field in form

I’m getting an “Object does not support this property or method” with the following:

<BODY onLoad=”document.frmCredentials.UserName.Focus();”>

I want the cursor placed in the UserName field when the document loads so the user doesn’t have to tab or click to it.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 06.2003 — [font=arial][color=maroon]Remember that JavaScript is case sensetive.[/color][/font]

[font=monospace]

<body onload="document.frmCredentials.UserName.focus();">

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@James_L_Oct 06.2003 — Hey Jona,

When I looked at the code I thought the "focus" should be lower case too, but shouldn't the "onload" still be "onLoad"?
Copy linkTweet thisAlerts:
@CharlesOct 06.2003 — [i]Originally posted by James L. [/i]

[B]Hey Jona,



When I looked at the code I thought the "focus" should be lower case too, but shouldn't the "onload" still be "onLoad"? [/B]
[/QUOTE]
[font=georgia]The actual name of the handler is [font=monospace]onload[/font]. In fact, in HTML and XHTML all element names are in lower case, it's just that HTML is case insensitive. XHTML and JavaScript are case sensitive and will not recognize [font=monospace]onLoad[/font].[/font]
Copy linkTweet thisAlerts:
@James_L_Oct 06.2003 — Hey Charles,

Thanks. So, the reason I have been using "onLoad" instead of "onload", with succcess, is because I started coding in HTML transitional, then switched to HTML strict, but still haven't gone to XHTML yet?
Copy linkTweet thisAlerts:
@CharlesOct 06.2003 — [i]Originally posted by James L. [/i]

[B]Hey Charles,



Thanks. So, the reason I have been using "onLoad" instead of "onload", with succcess, is because I started coding in HTML transitional, then switched to HTML strict, but still haven't gone to XHTML yet? [/B]
[/QUOTE]
[font=georgia]That, and you have never tried to address the handlers directly from JavaScript.[/font]
Copy linkTweet thisAlerts:
@James_L_Oct 07.2003 — Interesting...thanks for the info.
Copy linkTweet thisAlerts:
@JonaOct 07.2003 — [font=arial][color=maroon]Perhaps I can shed a little more light on the subject here. James, when Charles says "address the handlers directly from JavaScript" he means running it from JavaScript rather than an attribute of the BODY tag:[/color][/font]

[font=monospace]

document.onload=function(){alert("I am cool!")};

[/font]

[font=arial][color=maroon]You'd use the above instead of the case insensetive attribute: onLoad="alert('I am cool!');". You could use OnLoAd and get the same effect; however, if using document.OnLoAd you will get an error saying that OnLoAd is null or not an object (I believe that is the error). So, in XHTML, you'd have to use onload, and it is a good practice to use onload in HTML (strict or transitional doctype) rather than onLoad for when you port over to XHTML, as you will need to do eventually as it is the latest version of HTML and will be the new standard soon.[/color][/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@pyroOct 07.2003 — [i]Originally posted by Jona [/i]

[B]...for when you port over to XHTML, as you will need to do eventually as it is the latest version of HTML and will be the new standard soon.[/B][/QUOTE]
It already is the new standard...
Copy linkTweet thisAlerts:
@James_L_Oct 07.2003 — Thanks for the info guys.
Copy linkTweet thisAlerts:
@JonaOct 07.2003 — [i]Originally posted by pyro [/i]

[B]It already is the new standard... [/B][/QUOTE]


[font=arial][color=maroon]Oh well, you get my point.[/color][/font]

[b][J]ona[/b]
×

Success!

Help @lcscne spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...