Forum Moderators: open

Message Too Old, No Replies

Overflowing a <textarea>?

         

Emperor

9:29 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



Hi guys,

In my <input type="text"> elements I always set the 'maxlength' but you can't do that with a <textarea> so I was wondering what could happen if someone put in, say, a million characters. I guess it depends on where the form goes to, so let's say it's PHP, that means you get a PHP array with 1mil characters.

What do you guys think about the whole thing?

Take care,
Cyrus

iamlost

10:27 pm on Dec 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As you mention in HTML there is no way to set/limit the number of characters a user might input in a textarea.

I have read that some browsers put differing limits on input - 64KB to 128KB - but have never confirmed that. And those limits are high for most uses.

The only practical way to impose control is the use of scripting. As javascript may be turned off client-side scripting is less practical than server-side. There are lots of scripts out there - depending on your interface and preferred scripting language - do a search.

All form handling should be running multiple checks on input for data acceptability anyway - textarea length is just one of them.

kaled

10:02 am on Dec 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It may not be valid markup, but maxlength may work for textarea controls.

Windows 9X will typically set a limit of 64K characters. I believe, but am not certain, that NT/2000/XP does the same.

Certainly, Windows permits the maxlength to be set for multi-line edit controls so maxlength may work in some browsers.

Kaled.

scottmack

3:00 pm on Dec 5, 2004 (gmt 0)

10+ Year Member



Copied from a web site:

At the simplest, you could use just an onsubmit attribute in the form tag, containing JavaScript code like the following (for our sample form discussed above, with name="ourform" attached to it):

onsubmit = "return ok(42);"

with ok() defined as

function ok(maxchars) {
if(document.ourform.box.value.length > maxchars) {
alert('Too much data in the text box! Please remove '+
(document.ourform.box.value.length - maxchars)+ ' characters');
return false; }
else
return true; }