0

Is there a quick, easy way of limiting the amount of rows a user can enter in a textarea, using jquery/javascript?

Thanks,

Reindeer
  • 575
  • 1
  • 4
  • 11
  • Do you mean you want to restrict the size of the textarea or the amount of text that can be entered? – reggaemahn Jun 27 '13 at 14:35
  • @Joe I thought about something like that, but that would seem to ignore the case where you enter text that spans multiple lines and is soft-wrapped (no `\n`); for instance, I'm now on the 3rd "row" of this comment box, and yet I haven't inputted a single `\n`. – ken Jun 27 '13 at 14:38

1 Answers1

1

I don't think there's any concept of rows as it pertains to the user's input (the rows attribute is only concerned with the initial size of the element), and since some browsers (Chrome) allow you to easily resize textareas, anything you come up with wouldn't be fool-proof.

If anything, you should just figure out the rough amount of characters that you want to allow, and then check the length of the data.

ken
  • 3,650
  • 1
  • 30
  • 43
  • Ah OK. The problem is I'm creating an online form that users will need to fill in and print out and if they enter more rows that are visible into the textarea, anything that you need to scroll to get to won't get printed out. – Reindeer Jun 27 '13 at 14:53