473,903 Members | 5,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use of [ and ] within id or name attribute of <input /> tag



I am wanting to know whether [ and ] are XHTML1-valid characters for use
within an id attribute and/or a name attribute.

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

(e.g. see line 77) suggests that it is valid, but the spec suggests that
it is not.
More detail:

I have a form containing a variety of input elements, including a checkbox
array.

For ease of processing the form, it would be helpful if the name of each
element in the checkbox array could include [ ] e.g.

<input type="checkbox" name="formname[checkbox][number]" />

However, looking at the HTML4 spec, which XHTML1.0Transit ional piggy-backs
onto, the specification suggests that [ and ] are not valid characters for
use within this:

http://www.w3.org/TR/html401/types.html#type-name

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

However, a page I have online at present which uses [ ] does validate to
XHTML1.0Transit ional:

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

eg. line 77 contains name="main[function]"

Is [ and ] therefore valid?


Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22
www.lucas-smith.co.uk

Jul 20 '05 #1
4 21319


Martin Lucas-Smith wrote:

I am wanting to know whether [ and ] are XHTML1-valid characters for use
within an id attribute and/or a name attribute.

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

(e.g. see line 77) suggests that it is valid, but the spec suggests that
it is not.
More detail:

I have a form containing a variety of input elements, including a checkbox
array.

For ease of processing the form, it would be helpful if the name of each
element in the checkbox array could include [ ] e.g.

<input type="checkbox" name="formname[checkbox][number]" />

However, looking at the HTML4 spec, which XHTML1.0Transit ional piggy-backs
onto, the specification suggests that [ and ] are not valid characters for
use within this:

http://www.w3.org/TR/html401/types.html#type-name

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

However, a page I have online at present which uses [ ] does validate to
XHTML1.0Transit ional:

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

eg. line 77 contains name="main[function]"

Is [ and ] therefore valid?


When you look at
http://www.w3.org/TR/xhtml1/dtds.htm...onal.dtd_input
you will see that the name attribute of <input> is of type CDATA
therefore for XHTML 1.0 transitional the [] in a name attribute value of
an <input> element will pass validation with an XML parser.
The id attribute is defined to be of type ID and that doesn't allow [ or ].
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2


[Summary: Can anyone point me to a definitive reference of where the
allowed characters for a valid XHTML name attribute (of an input/form) tag
is, so I can make a regexp from this (or even also provide me with a
regexp!)?]
A while ago I posted to this list wanting to know whether [ and ] are
XHTML1-valid characters for use within an id attribute and/or a name
attribute. I need to apply this more generally now beyond just [].

Ultimately, I'm trying to get an regexp for validating a form API-supplied
name for both an input tag (<input name="something " ... /> and for a form
name <form name="something ">, i.e. in PHP

$formName = 'name';

$regexp = '[something]';
if (!ereg ($regexp, $formName)) {
'The form name must consist of characters....
}


I understand that in HTML4, [] and are allowed this is not the case:
http://www.w3.org/TR/html401/types.html#type-name

"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 that in XHTML the allowed characters are different (as I have been
told they include []) :

When you look at
http://www.w3.org/TR/xhtml1/dtds.htm...onal.dtd_input
you will see that the name attribute of <input> is of type CDATA
therefore for XHTML 1.0 transitional the [] in a name attribute value of
an <input> element will pass validation with an XML parser. The id
attribute is defined to be of type ID and that doesn't allow [ or ]. --


However, I can't see where exactly the CDATA type is defined for XHTML
Transitional, which is the doctype I'm using? Therefore:
** Can anyone point me to a definitive reference of where the allowed
characters for a valid XHTML name attribute (of an input/form) tag is, so
I can make a regexp from this (or even also provide me with a regexp!)? **

Martin

Jul 20 '05 #3
Martin Lucas-Smith wrote:
[Summary: Can anyone point me to a definitive reference of where the
allowed characters for a valid XHTML name attribute (of an input/form) tag
is, so I can make a regexp from this (or even also provide me with a
regexp!)?] [snip] I understand that in HTML4, [] and are allowed this is not the case:
> http://www.w3.org/TR/html401/types.html#type-name
>
> "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 (".")."
[snip]

You are confusing data types with attributes. The name attribute for the
<input> element type is clearly listed as being CDATA, not ID or NAME
tokens:

<URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.3>
<URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.4>

The only real restriction on what characters can appear in form control
names is when a form is submitted with GET:

"The "get" method restricts form data set values to ASCII characters."

-- <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1>

However, I can't see where exactly the CDATA type is defined for XHTML
Transitional, which is the doctype I'm using?

[snip]

<URL:http://www.w3.org/TR/REC-xml#attdecls>

--
Jim Dabell

Jul 20 '05 #4

[Summary: Can anyone point me to a definitive reference of where the
allowed characters for a valid XHTML name attribute (of an input/form)
tag is, so I can make a regexp from this (or even also provide me with
a regexp!)?]
You are confusing data types with attributes. The name attribute for
the <input> element type is clearly listed as being CDATA, not ID or
NAME tokens:


I must confess I don't fully understand how the spec is read :), hence my
question.

The only real restriction on what characters can appear in form control
names is when a form is submitted with GET:

"The "get" method restricts form data set values to ASCII characters."

-- <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1>

Erm, I'm strictly referring to what appears as XXX in the following:

<input name="xxx" ... />

Can anyone supply an unambiguous reference/regexp as to what xxx can be
for the page still to validate as XHTML?

Martin

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2473
by: Don | last post by:
Using PHP, I'm creating an <input> tag. How do you delimit the text string for the value parm of an <input> tag, when the string contains the delimit char? Example: <input...value="This text has a " in it"...> I tried preceeding the " with a the escape char \, but the browser apparently still used the embedded " as termination of the value string. One other thing...is the delimiter limited to just " and ' ?
3
2599
by: chirs | last post by:
Hi, I want to put a value in a cookie. The following code does not work. It does not store the box1.value in the cookie. How can I fix it? <input type="text" name="box1" onblur=document.cookie="user=" + box1.value> Chris
1
2491
by: Felipe Gasper | last post by:
Does anyone have thoughts on whether the text-transform attribute of input tags should apply to the displayed text in the browser? It's not *enclosed*, which I think is what the CSS2 spec refers to, and KHTML doesn't do this, but Gecko and IE both do. An example may be found at http://fshn3152.foods.uiuc.edu/~fgasper/test.php If you look at this page in IE or a Gecko-based browser, the input field's text will be in allcaps, but in...
3
13171
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like this, with a flush left margin:
3
12946
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input type=submit value='Done'> </form>
5
2269
by: Bart van Deenen | last post by:
Hi all I have a form with a couple of input fields, embedded within spans. I am using script.aculo.us for dragging and dropping, and want to reorder the input fields that way. The input fields are display:inline because I want them all on the same line. Does anyone know of a smart trick to be able to drag these input fields? Just setting their disabled attribute doesn't work, because then they get no events. Not setting disabled just...
2
3395
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given field(s). The popping-up seems to work just fine; it's the tearing down that's giving me grief. If I stick a onmouseout event on the same input field that caused the onmouseover/pop-up, it starts to flicker 'cos the <divis placed for esthetically...
1
1321
by: jodleren | last post by:
Hi I tried getElementById, it works in IE, but how I find items on a form properly? I can write a small for myself, but is there a function to find <inputitems on a form? That is, standard JS which also works in Mozilla WBR Sonnich
1
1444
by: =?Utf-8?B?U3VtaXQgUmF3YXQgSW5kaWE=?= | last post by:
What I have seen in Asp.net applications that if i put two Asp buttons on the web form(Aspx page) it generates multiple name attribute of input tag on the client side. for eg. <asp:Button ID="btn" value="first" runat="server" name="btnname"/> <asp:Button ID="Button1" value="second" runat="server" name="btnname"/> After the execution it shows the result in following way:--
0
11297
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10882
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7215
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6100
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4734
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4316
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.