4

How can i determine the number of lines in a <textarea> based on line wrapping ?

( There are no new line characters to be detected. )

Basically, I need a way to programmatically determine the average width of characters in the text area, so I can determine where it wraps (and determine the number of lines in this <textarea>).

This is for an application using Appcelerator

stealthdyno
  • 185
  • 2
  • 10
  • eh ? Can you please include an example or code or some pictures or anything more than what you have already ... – Manse Dec 08 '11 at 20:02
  • http://stackoverflow.com/questions/3697096/finding-number-of-lines-in-an-html-textarea is a similar question. The top answer should help you out. – Rion Williams Dec 08 '11 at 20:12
  • Thanks rionmonster, I found that posting, but what I'm not understanding is how taking the the width of the textarea divided by the length of an array of characters gives you the average width of characters... – stealthdyno Dec 08 '11 at 20:14

1 Answers1

0

SimpleCoder, a SO member, developed a plugin that tackles this same issue. You can find a description of it as well as a link to the plugin at the article below:

Textarea Line Count

Usage:

var result = $.countLines("#yourTextArea");
Community
  • 1
  • 1
Rion Williams
  • 74,820
  • 37
  • 200
  • 327
  • i can't use this plugin, or the span method, because its not a web application, its for development in appcelerator. just trying to get some clarification on a specific portion of what SimpleCoder did. – stealthdyno Dec 08 '11 at 20:18
  • Ah - Sorry, I noticed you mentioned Javascript so I assumed you were doing it in web development (and if you are using Javascript - this should work for your needs). You may want to consider asking SimpleCoder for some advice and perhaps some techniques that he used to accomplish it. – Rion Williams Dec 08 '11 at 20:24
  • Ahhh, i looked through his code a little closer, and I see what he did. That method isn't going to work for me, but it is definitely a clever solution! Thanks. – stealthdyno Dec 08 '11 at 21:03
  • No problem - best of luck on accomplishing this :) – Rion Williams Dec 08 '11 at 21:05