Click to See Complete Forum and Search --> : set focus on first field in form
lcscne
10-06-2003, 12:20 PM
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.
Remember that JavaScript is case sensetive.
<body onload="document.frmCredentials.UserName.focus();">
[J]ona
James L.
10-06-2003, 04:59 PM
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"?
Charles
10-06-2003, 05:03 PM
Originally posted by James L.
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"? The actual name of the handler is onload. 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 onLoad.
James L.
10-06-2003, 05:49 PM
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?
Charles
10-06-2003, 06:01 PM
Originally posted by James L.
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? That, and you have never tried to address the handlers directly from JavaScript.
James L.
10-06-2003, 07:29 PM
Interesting...thanks for the info.
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:
document.onload=function(){alert("I am cool!")};
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.
[J]ona
Originally posted by Jona
...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.It already is the new standard...
James L.
10-06-2003, 10:17 PM
Thanks for the info guys.
Originally posted by pyro
It already is the new standard...
Oh well, you get my point.
[J]ona