Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:41:46+00:00 2026-06-14T18:41:46+00:00

Possible Duplicate: How to get number of rows in <textarea >? I have a

  • 0

Possible Duplicate:
How to get number of rows in <textarea >?

I have a textarea and I write 7 lines in it with only 2 new line character like below, just imagine the following code box is a textarea and only twice the enter key is pressed.

 A text box, text field or text entry box is a kind of widget used when building
 a graphical user interface (GUI). A text box purpose is to allow the user to
 input text information to be used by the program.
 User-interface guidelines recommend a single-line text box when only one line of
 input is required, and a multi-line text box only if more than one line of input
 may be required.
 Non-editable text boxes can serve the purpose of simply displaying text.

After writing some more lines if now the textarea line count is n. How can I calculate the value of n?

Please be clear before you answer the question. I don’t want to count how many new line characters are there in my text like this one. How to get the number of lines in a textarea?

I want to count the number of lines as like as Microsoft Word count it from a passage.

no jQuery please…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:41:47+00:00Added an answer on June 14, 2026 at 6:41 pm

    you could try out this. i didn’t test it so far, but i remember this should work fine.

    var lineHeight = document.getElementById("yourTextarea").style.lineHeight;
    var scrollHeight = document.getElementById("yourTextarea").scrollHeight;
    document.getElementById("yourTextarea").style.height = scrollHeight; // this is just for showing purposes
    var numLines = Math.floor( scrollHeight / lineHeight );
    

    this should be the easyest way i think.

    EDIT

    so here is the answer, as simple as it is 😀

    first make shure to give the textarea a value for cols

    and now check this out =

    <textarea id="mytext" cols="10" rows="12">
    </textarea>
    <input type="button" value="Count Rows" onclick="countRows();"/>
    <script type="text/javascript">
    function countRows() {
        var stringLength = document.getElementById("mytext").value.length;
        var count = Math.ceil( stringLength / document.getElementById("mytext").cols ); 
        // just devide the absolute string length by the amount of horizontal place and ceil it
        alert( count );
    }
    </script>
    

    now this should work just as it should.

    UPDATE

    you also can make sure to remove all “new line” elements or just the last character IF it IS a “new line” in the string befor getting the length. this way there will no unwanted additional lines counted.

    ALSO be sure to NOT set the “width” of the textbox !! this will cause the text in a row to go further then the value of “cols”. that way the “count” value will give you the count of rows if would be with a max-row-width of cols value. so the only way to set the width of the textbox with the cols attribute.

    UPDATE 2

    i think if you want a non buggy way there is no way around using PHP or jQuery.

    also the second solution is just a quick and dirty way. you’d have to code a logic that checks each word if it is longer then the awaylable width and also check each row for words that have been put to the next row because of insufficient space.

    this will require some logical skills and due to inactivity i will not write the code for now.

    if you want me do post a complete Javascript, PHP or jQuery solution, please let me know.
    ( i don’t see any reason why to not use jQuery for this )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to get number of rows in <textarea >? I have a
Possible Duplicate: how to get the number of occurrences of each character using python
Possible Duplicate: How to get code point number for a given character in a
Possible Duplicate: How to get line count cheaply in Python? I'd like to print
Possible Duplicate: Error : get property of non-object I am new to codeigniter model,
Possible Duplicate: C# Get control by name I have been looking around for an
Possible Duplicate: Show line number in exception handling Can someone please tell me how
Possible Duplicate: How do we count rows using Hibernate? I want count number of
Possible Duplicate: Get a function's arity Say I have: function a(x) {}; function b(x,y)
Possible Duplicate: splitting a string i have a string which looks like this: http://pastebin.com/m5508ff19

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.