Forum Moderators: open
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
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.
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.
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; }