title: Force resizement when reading text from file
body: <p>The duplicate suggested is the question where I got the basis for this question, so it is <em>not</em> a duplicate! As a matter of fact, I <em>already</em> have linked to that question from the start...</p>
  
  <hr>
  
  <p>GOOD EDIT:</p>
  
  <p>I made a <a href="https://jsfiddle.net/n1c41ejb/" rel="nofollow noreferrer">JSFiddle</a> ( my first time :) ). Notice how the textarea does not expand as one would wish. Type something inside the textarea and it will get resized immediately.</p>
  
  <p>If we can automatically send a keypress event, it may work... (<a href="https://stackoverflow.com/questions/1468384/simulate-keypress-with-jquery">this</a> relevant question did not help, the answers had no effect).</p>
  
  <hr>
  
  <p>I am using the <code>textarea</code> as is from <a href="https://stackoverflow.com/a/19408351/2411320">here</a>. Then, I read from a file and I am putting the content inside the textbox, but it doesn't get resized as it should.</p>
  
  <p>I update the textbox like this:</p>
  
  <pre><code>function updateTextbox(text) {
    $('#cagetextbox').val(text);
  };
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>I am on firefox 34.0 canonical, at Ubuntu 12.04, if that plays some role, which I hope is not the case, since some of my users use Chrome.</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>An attempt would be to write something like this:</p>
  
  <pre><code>$('#cagetextbox').attr("rows", how many rows does the new text contain);
  </code></pre>
  
  <p>Note that if we try to <a href="https://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea">find out how many lines of text the textarea</a> contains, we will get 1 as an answer.</p>
  
  <hr>
  
  <p>EDIT_2</p>
  
  <p>Maybe something like <code>width/(length_of_line * font_size)</code>. For a few tests, it seems to be correct, if I subtracted 1 (by keeping only the integer part of the result of course).</p>