By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

naming syntax rules

P: n/a
I've just run into a weird quirk in IE where I had named form
elements like this: 2-some_name. IE was using just the numeric part as
an index in the form collection array. Boy, that took a while to figure out!

So, what are the rules for names and ids? I had thought this was
loosened up years ago.

Jeff
Jun 27 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Jeff wrote:
* *I've just run into a weird quirk in IE where I had named form
elements like this: 2-some_name. IE was using just the numeric part as
an index in the form collection array. Boy, that took a while to figure
out!

* *So, what are the rules for names and ids? I had thought this was
loosened up years ago.
| 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 (".").

http://www.w3.org/TR/REC-html40/types.html

--
Bart
Jun 27 '08 #2

P: n/a
On Apr 23, 3:12 pm, Bart Van der Donck wrote:
Jeff wrote:
> I've just run into a weird quirk in IE where I had named
form elements like this: 2-some_name. IE was using just the
numeric part as an index in the form collection array. Boy,
that took a while to figure out!
> So, what are the rules for names and ids? I had thought
this was loosened up years ago.

| 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 (".").

http://www.w3.org/TR/REC-html40/types.html
This is relevant for ID attributes, but NAME attributes are CDATA
(except for the NAME attributes of META elements, which are NAME
tokens) and so the preceding section of - REC-html40/types.html -
defines their restrictions. ('2-some_name' may not be a viable ID but
it is a valid NAME).
Jun 27 '08 #3

P: n/a
On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.comwrote:
| 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 (".").

Interesting that it doesn't allow []
Jun 27 '08 #4

P: n/a
On Wed, 23 Apr 2008 16:24:36 +0200, Captain Paralytic
<pa**********@yahoo.comwrote:
On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.comwrote:
> | 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 (".").


Interesting that it doesn't allow []
Not in ID's, but for PHP luckily in name attributes it's allowed :)
From http://www.w3.org/TR/html4/strict.dtd:

.....
<!ELEMENT INPUT - O EMPTY -- form control -->
<!ATTLIST INPUT
%attrs; -- %coreattrs, %i18n, %events --
type %InputType; TEXT -- what kind of widget is needed --
name CDATA #IMPLIED -- submit as part of form --
.....

So, just CDATA in name attributes.
--
Rik Wasmus
Jun 27 '08 #5

P: n/a
Henry wrote:
On Apr 23, 3:12 pm, Bart Van der Donck wrote:
>Jeff wrote:
>> I've just run into a weird quirk in IE where I had named
form elements like this: 2-some_name. IE was using just the
numeric part as an index in the form collection array. Boy,
that took a while to figure out!
So, what are the rules for names and ids? I had thought
this was loosened up years ago.
| 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 (".").

http://www.w3.org/TR/REC-html40/types.html

This is relevant for ID attributes, but NAME attributes are CDATA
(except for the NAME attributes of META elements, which are NAME
tokens) and so the preceding section of - REC-html40/types.html -
defines their restrictions. ('2-some_name' may not be a viable ID but
it is a valid NAME).
Oddly, in practice, it works the other way. All browsers I tested
recognized the number first for IDs, IE failed for number first for form
element name. Of course, IE's quirks are legion.

With that said, I'll rewrite my IDs for this particular app to conform.

Jeff
Jun 27 '08 #6

P: n/a
Henry wrote:
On Apr 23, 3:12 pm, Bart Van der Donck wrote:
>Jeff wrote:
>> I've just run into a weird quirk in IE where I had named
form elements like this: 2-some_name. IE was using just the
numeric part as an index in the form collection array. Boy,
that took a while to figure out!
So, what are the rules for names and ids? I had thought
this was loosened up years ago.
| 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 (".").

http://www.w3.org/TR/REC-html40/types.html

This is relevant for ID attributes, but NAME attributes are CDATA
(except for the NAME attributes of META elements, which are NAME
tokens) and so the preceding section of - REC-html40/types.html -
defines their restrictions.
Full ACK.
('2-some_name' may not be a viable ID but it is a valid NAME).
^^^^
I think you meant `name' in the sense of "value of the `name' attribute of
`form' elements or form controls" here, for the above definition makes it
very clear that ID and NAME tokens have the same restrictions.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #7

P: n/a
Captain Paralytic wrote:
On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.comwrote:
> | 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 (".").

Interesting that it doesn't allow []
It does not need to. Apparently you haven't been paying attention.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #8

P: n/a
Rik Wasmus wrote:
[...] Captain Paralytic [...] wrote:
>On 23 Apr, 14:12, Bart Van der Donck <b...@nijlen.comwrote:
>> | 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 (".").

Interesting that it doesn't allow []

Not in ID's, but for PHP luckily in name attributes it's allowed :)
[...]
Not in *all* `name' attribute *values*, but in most, including those
relevant here.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.