This flows from the error I ran into here jQuery $(’form’).serialize() returns only one element of a form serialized where having a form tag named "elements", like so:
<form>
<input name="elements"/>
<input name="e2"/>
</form>
prevents you from accessing all the named elements of the form with jQuery's $('form').serialize() (i.e. you get "elements=" where you should get "elements=&e2=").
I'd like to have more general information about what proper "name" elements of form tags. I.e. what are the off-limits tags ("elements", "name", etc.), and what are the valid characters for a name. Are these things defined in a standard, or a reference manual, or is it trial and error?
Thoughts and input appreciated.
Thanks for reading.
Ancient question, but still applies to this day...
With forms, you cannot have an input with the same name as a form property per se. There is no hard restriction, but whatever you do will overwrite a form's attributes. The list of form attributes is extensive, varies by browser and JS engine, and could change at any time without notice. Therefore a static list would be of no use.
A form's property value will be overwritten with a reference to any field having the same name as that attribute. IE: if you have a field named "action", then the form's action attribute will be overwritten with a reference to that element named "action". Without an input named "action":
form.action
is a URL. With an input named "action"form.action
is an element. Some explanation found here: Why JS function name conflicts with element ID?. "name", "action" or "id" might be a preferred name of a form field, and the JS world never accounted for that.There is a save from this complete failure of the JS world: It is noted by a commenter on MSDN (http://msdn.microsoft.com/en-us/library/ie/ms536429%28v=vs.85%29.aspx) to instead use the
getAttributeNode()
method of the form object to get the real form property value. Works in FF current and IE ~7. With this method, you can have a field with the same name as a form element attribute. This should allow one to decouple HTML/JS restrictions from API's simultaneously serving various other client types.Given your initial problem I suspect it is just trial and error, or a deep knowledge of the libraries that you are using (which can be unrealistic, granted).
Certainly, stick with alpha characters, but it ought to be ok to append numeric to the end.
A bugbear for many in ASP.NET that adds a dollar notation to the name tag might help, so you could give that a try. I certainly be interested to see what happens.
As far as I'm aware there are no "reserved words" as such, so provided the criteria regarding valid characters (no spaces, punctuation and must start with letter) is met then the name attribute can contain anything.