How to count numbers of line in a textarea

I want to make a dynamic textarea, it should increase in rows as the content increase.

I am using this code:

$("#text_textarea").keyup(function(e) {
    //splitting textarea value wrt '\n' to count the number of lines
    if ($(this).val().lastIndexOf('\n')!=-1)
    var x = $(this).val().split('\n');
    $(this).attr( "rows" , x.length+1 );
});

But it fails when user continues to write without giving any new line \n (pressing Enter).

46 thoughts on “How to count numbers of line in a textarea”

  1. Heya! I’m at work browsing your blog from my new apple iphone!
    Just wanted to say I love reading through your blog and look forward to all your posts!
    Carry on the great work!

    Reply
  2. It’s really a nice and useful piece of information. I’m glad that you simply shared this helpful information with us.
    Please keep us up to date like this. Thanks for sharing.

    Reply
  3. I’ve been surfing online more than 2 hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all web owners and bloggers made good content as you did, the
    net will be much more useful than ever before.

    Reply
  4. What i do not understood is in truth how you are no longer really a lot more smartly-preferred than you may be right now.
    You are very intelligent. You already know thus considerably relating to this matter, made me individually believe it
    from so many varied angles. Its like women and
    men don’t seem to be interested until it’s one thing
    to accomplish with Lady gaga! Your personal stuffs outstanding.
    At all times deal with it up!

    Reply
  5. Does your site have a contact page? I’m having a tough time locating it but, I’d like to send you an email.

    I’ve got some suggestions for your blog you might be interested in hearing.
    Either way, great website and I look forward to seeing it grow over time.

    Reply
  6. Its such as you learn my mind! You seem to grasp a lot approximately this, like
    you wrote the book in it or something. I believe that you simply can do with
    a few p.c. to power the message house a bit, but instead of that, that is magnificent blog.
    A fantastic read. I’ll definitely be back.

    Reply
  7. I don’t even know how I ended up here, but I thought this post
    was great. I do not know who you are but definitely you
    are going to a famous blogger if you aren’t already 😉 Cheers!

    Reply
  8. Yesterday, while I was at work, my cousin stole my iphone and tested to see if it can survive a 30 foot
    drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views.
    I know this is totally off topic but I had to share it with someone!

    Reply
  9. Hi! I could have sworn I’ve been to this website before but after browsing through some
    of the post I realized it’s new to me. Nonetheless, I’m definitely happy I found it and
    I’ll be book-marking and checking back often!

    Reply
  10. Hello There. I found your weblog the usage of msn. That
    is a really well written article. I will be sure to bookmark it and come
    back to read extra of your useful information. Thank you
    for the post. I will definitely comeback.

    Reply
  11. Howdy! This is kind of off topic but I need some advice from an established blog.
    Is it difficult to set up your own blog? I’m not
    very techincal but I can figure things out pretty quick.
    I’m thinking about making my own but I’m not sure where to begin.
    Do you have any ideas or suggestions? With thanks

    Reply
  12. Hello there! This blog post could not be written any
    better! Looking through this post reminds me of my previous roommate!

    He continually kept talking about this. I will send this information to
    him. Fairly certain he will have a very good read.
    I appreciate you for sharing!

    Reply
  13. An intriguing discussion is definitely worth comment.
    I think that you ought to write more on this topic, it may not be a taboo matter but generally folks don’t talk about such issues.
    To the next! Many thanks!!

    Reply
  14. Fantastic beat ! I would like to apprentice even as you amend
    your web site, how could i subscribe for a weblog website?
    The account helped me a acceptable deal. I were tiny bit acquainted of
    this your broadcast provided vivid transparent concept

    Reply
  15. We absolutely love your blog and find the majority of your post’s to be precisely what I’m looking for.
    Would you offer guest writers to write content for you personally?
    I wouldn’t mind composing a post or elaborating on some of the
    subjects you write with regards to here. Again, awesome web log!

    Reply

Leave a Comment