views:

380

answers:

3

Do different browsers (Firefox/Safari/IE/Opera) have different limits on the length of the "name" attribute of form elements?

   <input name='a012345678901234567890123456789012345678901234567890123456789 ...'>
A: 

HTML spec:

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

Maximum length is NOT specified.

vartec
Thanks, thats very helpful. Although I was wonder what the different browser limits are. I bet Firefox/IE/Safari/Opera implement different hard limits. Thanks!
Bob Herrmann
I've only had problems with this in IE, where whole URL is limited to 2048 bytes.
vartec
I see now in my question I forgot to call out that I was after the length restriction. Sheesh. It's easy to write a bad question.
Bob Herrmann
A: 

Short answer: No, there are no limits other then what what characters can be used (A-Z, 0-9, "-", "_", ".", ":", and must start with letter)

Long answer: Probably, though if you are hitting those limits you are doing something very, very wrong. The first browsers to fail would be cell phone browsers, where memory is at a real premium. In those cases the browser may either crash, or only use the first x characters of the name. But the bottom line is you shouldn't be pushing those limits - if you need a unique name, just use a GUID. If you need to encode a bunch of meta-information, the field name is the wrong place to put it (stick it in a matching hidden field called *input_name*.metadata)

David
A: 

I don't think you will reach the maximum length for the usual browsers. I haven't seen a very long "name" attribute so far, but ASP HTML code often has very long strings in it like this one:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="eoR/9oFJY7x1fwy2bYuP+si4g80sNmQNAyTEWindlIuh
/sy+xAs0bFI1ygCuhB4Ceou6RZH4vO760FTZA7SdwD... [about 20 KB more]"

So I guess the maximum length for all the attributes will be much more than the 1024/32768 bytes you're probably worrying about.

schnaader