How to calculate textarea cols with 100% width?
Posted
by
sehwoo
on Stack Overflow
See other posts from Stack Overflow
or by sehwoo
Published on 2010-12-28T17:49:00Z
Indexed on
2010/12/28
17:54 UTC
Read the original article
Hit count: 187
I set the width of a textarea to 100%, but now I need to know how many characters can fit in one row.
I'm trying to write a javascript function to auto-grow/shrink a textarea. I'm trying to keep from using jquery since I just need this one function.
My logic is to rows = textarea.value.split('\n')
, iterate through rows
and count += rows[i].length/textarea.cols
, then count += rows.length
, and finally textarea.rows = count
. The only problem is that count
is too large because textarea.cols
is too small.
© Stack Overflow or respective owner