Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you could try out this. i didn't test it so far, but i remember this should work fine.</p> <pre><code>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 ); </code></pre> <p>this should be the easyest way i think.</p> <p><strong>EDIT</strong></p> <p>so here is the answer, as simple as it is :D</p> <p>first make shure to give the textarea a value for <strong>cols</strong></p> <p>and now check this out =</p> <pre><code>&lt;textarea id="mytext" cols="10" rows="12"&gt; &lt;/textarea&gt; &lt;input type="button" value="Count Rows" onclick="countRows();"/&gt; &lt;script type="text/javascript"&gt; 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 ); } &lt;/script&gt; </code></pre> <p>now this should work just as it should.</p> <p><strong>UPDATE</strong></p> <p>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.</p> <p>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.</p> <p><strong>UPDATE 2</strong></p> <p>i think if you want a non buggy way there is no way around using PHP or jQuery.</p> <p>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.</p> <p>this will require some logical skills and due to inactivity i will not write the code for now.</p> <p>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 )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload