We help IT Professionals succeed at work.
Get Started

Javascript Resizing Textarea

purdyra1
purdyra1 asked
on
320 Views
Last Modified: 2012-05-12
I used this code and overall it worked great BUT for some reason if I type in 18 characters it works fine, but if I type in 19 characters it grows by 2 lines instead of one, so by the time I enter 30 different lines, I have 30 extra lines at the bottom instead of just 1 or 2 extra lines at the bottom. I tried expanding the textbox width but that didn’t seem to help at all. Any small change I can make to the code or any idea of anything I can do, I really need this functionality and it’s great, thank you!


  <script type="text/javascript">
    function sz(t) {
                    a = t.value.split('\n');
                    b=1;
                    for (x=0;x < a.length; x++) {
                     if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
                     }
                    b+= a.length;
                     if (b > t.rows) t.rows = b;
                    }

I got the code from here.  
http://scvinodkumar.wordpress.com/2009/05/28/auto-grow-textarea-doing-it-the-easy-way-in-javascript/
Comment
Watch Question
Test Developer/Validator
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE