title: Resize textarea to fit all content
body: <p>I'm trying to resize a textarea to fit the content in it, as tightly as possible. Here's my current effort:</p>
  
  <pre><code>function resizeTextarea(t) {
  a = t.value.split('\n');
  b = 1;
  for (x = 0; x &lt; a.length; x++) {
      c = a[x].length;
      if (c &gt;= 75) b += Math.ceiling(c/75);
      }
  b += a.length;
  t.rows = b;
  }
  </code></pre>
  
  <p>This works fairly well, but seems to fail when the user "pushes" text onto the next line by filling up the width. (Note: the 75 used here is representative of the width of my textarea in characters)</p>
  
  <p>There's also an odd effect where [enter][key] makes the textarea 2 lines past the end of the text, then the next [key] takes it back to the expected one extra line. I've tried just setting c to 2 if c&lt;=1, with no effect. This one isn't a huge deal, but it would be nice to correct.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Note: this function is called on key down.</p>