I need to have a textarea that allows the user to enter only 2 lines of text.
I accomplished this by e.preventDefault() on a keyDown event when lineCount equals 2. The problem is when the user uses backspace, and deletes entered text.
How do I keep track of lines and allow typing again until the user enters two lines again?
Here is what I was able to accomplish:
var lineCount = 0;
$('#editor').keydown(function (e) {
if (e.keyCode == 13) {
lineCount++;
}
if (e.keyCode == 8) {
//needs to remove characters, deduct linecount when it gets to first line and reinstate typing
return true;
}
if (lineCount >= 2) {
e.preventDefault();
return false;
}
});