homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

XHTML Strict javascript and form ID

10+ Year Member

Msg#: 271 posted 7:24 am on Jan 28, 2003 (gmt 0)

Hello all,

I am rewriting a web site in XHTML 1.0 strict and I have run up against a problem with the fact that Name is no longer an attribute of Form. In earlier versions of HTML I could reference specific form fields with javascript...

For example: document.myform.myfield.focus() would put the focus in the field myfield in the form myform.

In XHTML Strict where Name is no longer allowed as form identifier this does not work. Does anyone know how I can work around this problem? Thanks.



WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 271 posted 7:51 am on Jan 28, 2003 (gmt 0)

Welcome to Webmaster World!

All you have to do is give the individual fields an ID (the form doesn't need one) .. and refer to those ID's.

For example, consider the following code:

<input type="text" id="mytextfield" \>
<input type="password" id="blah" \>

To refer to the first field you use:


Likewise, to refer to the second field you use:


Simple, all you have to remember is the ID, and call it directly using getElementById


10+ Year Member

Msg#: 271 posted 8:42 am on Jan 28, 2003 (gmt 0)

Thanks a lot, getElementById() does work :) However, I now have an additional problem. The input field where I want to put the focus is in a four-frame document. The frame that contains the input field loads first and I can see that it gets focus for a fraction of a second, but when the other frames finish loading the input field looses its focus again. Any ideas on how this can be solved?

My web site is generated dynamically so putting the getElementById() call in the last frame to load is not a practical solution since each frame are semi-independent from one another.



10+ Year Member

Msg#: 271 posted 9:04 am on Jan 28, 2003 (gmt 0)

Okay...figured it out. Had forgot that I at some point had put some onload="self.focus()" calls in various pages. These were the ones that broke the input field focus. So, thanks again for the help...I sure do appreciate it!


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved