XHTML Strict and Forms
Did you know that with XHTML Strict, a <form>
element can't have a name
attribute? Actually, the only required attribute is action
. But, if you do want to identify your form, then you have to use the id
attribute. The problem with this is that many of us web developers are used to referencing a form (with Javascript) with document.formName
. So as a service to my readers, if you do decide to XHTML 1.0 Strict, you will need to reference your forms (in Javascript) using one of the following syntaxes. For the sake of this example, pretend our form is named "webForm":
document.getElementById("webForm);
// assuming it's the first form on the page.
document.forms[0];
document.getElementsByTagName("form").item(0);
Of course, if you're trying to get the value <input> tag within your form, and that input has an id
attribute, you can just get that using document.getElementById("inputId");
.
You ask - what insired you to post this? Well, the Struts enhancement to produce XHTML-compliant code from the tag libraries. It was closed yesterday, and they seemed to have missed this - in other words, the <form>
still has a name
attribute. It'll be interesting to see how they resolve this. I'm hoping that Struts is not tied to the name
attribute at all, and the fix just requires a bunch of fixes to Javascript that is written (by the tags).