homepage Welcome to WebmasterWorld Guest from 54.196.69.189
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
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
bitstearm




msg:1480496
 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.

 

DrDoc




msg:1480497
 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:

document.getElementById('mytextfield').value

Likewise, to refer to the second field you use:

document.getElementById('blah').value

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

bitstearm




msg:1480498
 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.

Thanks.

bitstearm




msg:1480499
 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!

Cheers

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved