[Javascript] 'name' property in forms not XHTML valid
Howard Jess
howard at dhitechnologies.com
Tue Jan 24 12:42:27 CST 2006
On 1/24/06, Jonathan Gold <johnnyclock at gmail.com> wrote:
> function clearColors()
> {
> for (var i = 0; i < 3; i++)
> {
> document.formColors.elements[i].value="";
> }
> }
>
> And in the markup I use the following:
>
> <form id="formColors" name="formColors" action="">
[snip]
>
> PROBLEM: nowadays, I am trying to write valid XHTML. I seem to need
> the form's NAME attribute for the purpose of the javascript, but the
> HTML validator tells me:
>
> <quote>
> This page is not Valid XHTML 1.0 Strict!
> Below are the results of checking this document for XML
> well-formedness and validity.
>
> 1. Error Line 104 column 27: there is no attribute "name".
>
> <form id="formColors" name="formColors" action="">
>
> You have used the attribute named above in your document, but
> the document type you are using does not support that attribute for
> this element… </quote>
Without even looking (dangerous!) I'd believe the validator. Elements
within a form (INPUT, SELECT, TEXTAREA, etc.) can still use the NAME
attribute, but it's not legal on a FORM. Changing your script function to
function clearColors() {
var form = document.getElementById('formColors');
if (form != null)
for (var i=0; i<3; i++)
form.elements[i].value = "";
}
should work.
hj
More information about the Javascript
mailing list