Is it possible to limit the number of lines in a text area ?,
I have a text area, in which i have to limit the number of lines up to
3,
How can i done this?, I wrote the tag as
<textarea name="short_desc" id="short_desc" cols="25" rows="3" ></
textarea>
But this doesn't help me, pls reply
Hi, i've had to solve this problem today. Its true that you can't
solve this with HTML. But the javascript to achieve it is quite
simple, my solution is as follows:
This is for a textarea that is being used as an address entry box, i'm
limiting it here to four lines but you can change it to whatever size
you need
1) Attach some javascript to the onkeyup event of the textarea
2) Split the textarea string into an array using split() on the \n
char
3) Count the number of lines in the textarea by getting the number of
elements in the newly created string array
4) Setting the value of the text area equal to lines 1,2,3
5) Making the string in the array for line 4 equal to a substring of
itself that is missing the last character (else you end up with 4
lines and a newline)
6) Output a notice to the user that the input field has too many
lines.
The code looks like this:
onkeyup="var newlineCount = this.value.split('\n');
if(newlineCount.length>4) { this.value =
newlineCount[0]+newlineCount[1]+newlineCount[2]+
(newlineCount[3].substr(0,newlineCount[3].length-1)); alert('Maximum
Address Size: Four Lines');}"
Hope this is useful,
Regards,
John.