"Simon" <si*******@planet.nl> wrote in message
news:bg*********@reader11.wxs.nl...
Vjekoslav..
You've been very helpful sending me this script, it workes well but i have
a question.
When I type text in this textarea without hiiting return on my keyboard
it's possible to exceed the limit off lines.
For example a textarea with your code and a maximum of 4 rows:
[textarea]
1111111111111
2222222222222
3333333333333
4444444444444
When I would go on typing (55555555555) i could get to the 5th line
without an alert!
Could you perhaps look into that? It's very important to me that no one
can exceed the limit in lines set by the rows.
Thank you in advance,
Simon
If you know the number of columns as well as the number of rows, you can
also trap the number of characters from being exceeded. The total possible
number of characters is the product of rows and columns. You can check how
many characters are in a form element like this:
tbox = document.getElementById('sometextbox');
if(tbox.value.length > (rows * cols)) {
tbox.value = tbox.value.slice(0, -1);
alert('I\'m watching you! Stop typing, and read the form
description.');
}
This would work in conjunction with the line break ("\n") checks since that
means the rows are being ended "prematurely" and therefore can not exceed
the total number of characters in your text box.
By the way, if this is "very important," you can't count on JavaScript to
keep people from turning scripting off and pasting a copy of "The Complete
Works of Shakespeare" in your textarea. You should also check the length of
user input in your form handler on the server. If this is only "mildly
important," you can probably trust JavaScript to only goof on you <10% of
the time.
HTH,
Zac