I wanted to modify "user.module" to focus the cursor on the "Username" field when the page is loaded. Adding the following function did create the correct content for the "body" tag.

function user_onload () {
    return 'document.login.edit[name].focus()';
}

I also added 'name="login"' to the form tag. However the focus is not correctly set on page load, because of the square brackets used in the form name (edit[name]).

In XHTML (or HTML?) the "name" tag must be CDATA which is defined as:

CDATA is a sequence of characters from the document character set and may include character entities.

In addition:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

So if I am thinking clearly today, this module is producing invalid markup and can't easily be modified the way I would like. It also uses these type of names in form selects statements...

So I looked a bit further and found the following occurences:

linbox:/var/www/drupal-cvs# grep -c -r -i 'name=\\\"edit\[' * | grep -v 0\$
includes/common.inc:9
modules/taxonomy.module:1
modules/forum.module:2
modules/user.module:8
modules/profile.module:2
modules/system.module:1
modules/import.module:1

Perhaps it needs a rethink on how the values of the $edit[] array is passed back and forth between the client and the server?

cheers,

Mark.

Comments

matt westgate’s picture

This doesn't address your concerns of valid xhtml, but you can access the javascript dom the following way:

function user_onload () {
    return "document.forms['login'].elements['edit[name]'].focus";
}
ax’s picture

"edit[whatever]" is a perfectly valid value for the "name" attribute of <input>, <select>, <option>, <textarea> - for all html elements where it is defined as CDATA in the DTD. CDATA includes "[" and "]". you mix up "name" /attribute/ and /token/ - see http://www.htmlvalidator.com/phorum/read.php?f=2&i=469&t=185 for details. so your conclusion about invalid xhtml production is wrong and i am CLOSING this bug.

if you want to reference a "form" element, don't use the "name", but the "id" attribute. <q cite="http://www.w3.org/TR/xhtml1/#h-4.10">Note that in XHTML 1.0, the name attribute of [the a, applet, /form/, frame, iframe, img, and map] elements is formally deprecated, and will be removed in a subsequent version of XHTML.</q> the "id" attribute, in contrast to the "name" attribute, is of type ID and it's values restricted as you mentioned.