tags:

views:

104

answers:

6

What is the "natural" number of allowed characters in an input field in html?

thanks a lot

addition due to the comments

i don't need to send it to the server via post or get. i am going to parse the string via JS.

So if the input is unlimited like @sAc says brings me to two further questions:

  1. What is the longest String JS can handle?
  2. what is the lowest amount of allowed characters for an input in common browsers?(which would be my limit than)
+1  A: 

When the type attribute has the value "text" or "password", this attribute specifies the maximum number of characters the user may enter. This number may exceed the specified size, in which case the user agent should offer a scrolling mechanism. The default value for this attribute is an unlimited number.

Source: http://www.w3.org/TR/html401/interact/forms.html#adef-maxlength

Sarfraz
but nobody knows / has tested how the limitation in common browsers is, isn't it?
helle
This limitation probably varies across browsers, JS implementations, server implementation, and possibly even physical hardware limits. This is a textbook example of [undefined behavior](http://en.wikipedia.org/wiki/Undefined_behavior).
Justin L.
@Justin L: Yup that true too.
Sarfraz
A: 

I wouldn't think there is a limit, unless the code has something stopping it (size parameter) or the server can't take any more characters (either a LOT of characters or a bad server).

There is also the 32bit etc. limits depending on the server, I believe.

Sam
I think size-parameter is not quite right? To limit the maximum chars of a field, you have to use the `maxlength`-attribute. Size is only for visual width of the field.
faileN
ah apologies, yes, you are correct.
Sam
A: 

I think that depends on the method you are sending the form with. If you send the form via GET-method it's only 255 chars for the whole query (correct me if I am wrong). The POST-method allows much more...

So in the end you can write millions of chars in a text-field, the question is, if all chars are sent to the server.

In HTML however you've got the possibility to specify how many characters you want to allow. Look at this snippet:

<input type="text" name="email" maxlength="255" />

The maxlength-attribute of the tag, prevents the user from being able to type in more than 255 chars.

faileN
A: 

In a textarea you can enter an unlimited amount of text.

OK, in practice you shouldn't enter megabytes of text or you will run into server limits.

When you the POST method to send the form to the server (which is the usual way), then you can send at least megabytes. When you use the GET method, the whole form is transferred through the querystring and there the limits are in the thousands of characters (the exact value depends on the server and the browser).

Hans Kesting
A: 

The number of visible characters is dependent on the size of the input element, but also on the style of that element: a wide box put in a shallow container (e.g., a div or form) will not show all the characters in the field.

See W3Schools explanation on INPUT, paying attention to size and maxlength attributes. maxlength specifies the maximum length (in characters) of an input field for "text" or "password" types, size specifies the width of an input field.

jschulenklopper
+2  A: 

Firefox 3.6.6 on my 32 bit Win 7 machine becomes slow after 1,000,000 characters and totally freezes after 4,000,000.

Chrome crashes somewhere after 8,000,000.

IE8 crashes somewhere after 8,000,000.

Safari crashes somewhere after 2,000,000.

In my testing Chrome/IE8/Safari don't slow down as the size goes up the way Firefox does.

Sam