Forum Moderators: open
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.
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
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.