Specify and Limit number of lines in textarea and display line count using jQuery?

Html: Lines used: 0 js: $(document). Ready(function(){ var lines = 10; var linesUsed = $('#linesUsed'); $('#countMe'). Keydown(function(e) { newLines = $(this).val().

Split("\n"). Length; linesUsed. Text(newLines); if(e.

KeyCode == 13 && newLines >= lines) { linesUsed. Css('color', 'red'); return false; } else { linesUsed. Css('color', ''); } }); }); fiddle: http://jsfiddle.net/XNCkH/17.

Samuel Liew, thank you so very much! I'm sure this will be helpful to a lot of people. – chainwork Jun 28 at 15:21 The return false does not seem to be working when I paste in a large number of lines.Is there a way this can be modified to ensure a user cannot submit the form if the number of allowed lines has been exceeded?

– chainwork Jun 28 at 16:04.

Regarding your other comment on the other answer, try this: if(e. KeyCode == 13 && newLines >= lines) { linesUsed. Css('color', 'red'); $(this).

Parents('form'). Submit(function() { return false; }); return false; } else { linesUsed. Css('color', ''); $(this).

Parents('form'). Submit(function() { return true; }); }.

That works Sam, I just added one more return true; in the else. – chainwork Jun 28 at 16:21 1 That shouldn't be necessary, because it returns null by default, which allows the next enter key. In the original code, the return false prevents the enter key from being pressed if there are already maximum number of line breaks.

– Samuel Liew Jun 29 at 1:49 thanks, this helped me too – Samuel Liew Jul 2 at 8:07.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions