Can tag name begin with a "-" character?

S

Seeker

Hi!

Is it acceptable to start an element name with a "-" character? For
example...

Username 1:<input name="UserPass1" size="32"><br>
Password 1:<input name="-UserPass1" size=16"><br>


....I'm doing some form processing and I'm trying to find a generic way to
identify a form element that relates to the previous one. Basically, if an
element doesn't begin with a dash, add a <BR> tag before appending it's
value.

Alternately I could identify the prior element like this...

Username 1:<input name="+UserPass1" size="32"><br>
Password 1:<input name="UserPass1" size=16"><br>

.... and only append <BR> tags to the end of values if the name does not
begin with a "+"

I just want to be sure I can use non alpha characters at the beginning of an
element name. (If there are better characters than "+" or "-" to use I'd
appreciate knowing.)
 
S

spaghetti

I just want to be sure I can use non alpha characters at the beginning
of an element name.

As far as I know you can, there really aren't any restrictions on that
sort of thing in the spec (that I could see) and it validates. I'm not
sure why you can't just use more specific names though, like username and
password instead of userpass and -userpass.
 
R

Richard

Seeker said:
Is it acceptable to start an element name with a "-" character? For
example...
Username 1:<input name="UserPass1" size="32"><br>
Password 1:<input name="-UserPass1" size=16"><br>

...I'm doing some form processing and I'm trying to find a generic way to
identify a form element that relates to the previous one. Basically, if
an element doesn't begin with a dash, add a <BR> tag before appending
it's value.
Alternately I could identify the prior element like this...
Username 1:<input name="+UserPass1" size="32"><br>
Password 1:<input name="UserPass1" size=16"><br>
... and only append <BR> tags to the end of values if the name does not
begin with a "+"
I just want to be sure I can use non alpha characters at the beginning of
an element name. (If there are better characters than "+" or "-" to use
I'd appreciate knowing.)

why not use "a-username" and "b-userpass"?
 
T

Toby A Inkster

Seeker said:
Is it acceptable to start an element name with a "-" character?

From the HTML 4.01 spec, section 6.2 "SGML Basic Types"
<http://www.w3.org/TR/html401/types.html#h-6.2>:

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

Jukka K. Korpela

Toby A Inkster said:
Is it acceptable to start an element name with a "-" character?

From the HTML 4.01 spec, section 6.2 "SGML Basic Types"
<http://www.w3.org/TR/html401/types.html#h-6.2>:

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

But this isn't about an ID or NAME token. Neither is it about tag name
or element name, of course.

The name="..." attribute in HTML is misleadingly named, since it is
_not_ defined being of type NAME, except in the meta element. See
http://www.w3.org/TR/html4/index/attributes.html

This is about the value of the name attribute in an input element, and
that attribute is declared with CDATA value. This means that any string
is accepted by the HTML specifications. However, the effect of form
submission, when the default enctype is used, is defined only in the
case where the data (including field names, or "control names") is
Ascii.

Hence, any Ascii character can be used inside name="..." in an input
element, naturally with the usual HTML rules for writing the quotation
mark in such a context or the less than sign or the ampersand anywhere.

The rest depends on the form handler. If it can deal with a hyphen,
fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top