Hello,
I'm modifing a phpforum and would like to know if it's possible to make a textarea limited. This is, if the text get's to the end of the textarea box I don't want it to scroll down for the next line. Just stop there. I tried the javascript that limits the characters but it doesn't work because if the user press enter it counts just one char and it gets out of the textbox.
I hope you understand what I mening. Excuse mi english please
Thanks Gabriel
I need some help with a textarea
Moderator: General Moderators
PHP won't do a thing with a <textarea> as PHP is serverside. What you are looking for is a Javascript solution.
Off the top of my head, have an "onChange='myFunctionCalledCountChars()'" in the <textarea> so that every time a key is pressed, Javascript knows how many were input already. Once the limit is reached, cancel the event.bubble and return false;
Off the top of my head, have an "onChange='myFunctionCalledCountChars()'" in the <textarea> so that every time a key is pressed, Javascript knows how many were input already. Once the limit is reached, cancel the event.bubble and return false;
\r
At least in Windows the textarea uses the \r for a new line so you can count how many \r are in the field and stop it once you reach the limit.
Know you have something more to learn ereg expressions or string searches.
If \r doen't work try \n or both togther \r\n It has been a while since I dealt with it but I seem to remeber having to do something similiar
Know you have something more to learn ereg expressions or string searches.
If \r doen't work try \n or both togther \r\n It has been a while since I dealt with it but I seem to remeber having to do something similiar
I've tested the event-bubbling of keyboard-input and, using onKeyDown and onChange for <textarea> both cancelling the even-bubble and returning false couldn't stop that text was entered into a field after a certain condition (i.e. text-length of the textarea) was met.
I would suggest you do use PHP to determine the string-length and, if too long, have the user re-submit the form, i.e. shorten the text.
Alternatively, you could spew out a warning that the text-limit has been reached if the user is inputting further text.
I would suggest you do use PHP to determine the string-length and, if too long, have the user re-submit the form, i.e. shorten the text.
Alternatively, you could spew out a warning that the text-limit has been reached if the user is inputting further text.