title: How to limit the number of characters and lines in the textbox using javascript?
body: <pre><code>&lt;script type="text/javascript"&gt;
  function checking(textarea, maxLines, maxChar) {
      var lines = textarea.value.replace(/\r/g, '').split('\n'), lines_removed, char_removed, i;
      if (maxLines &amp;&amp; lines.length &gt; maxLines) {
          lines = lines.slice(0, maxLines);
          lines_removed = 1
      }
      if (maxChar) {
          i = lines.length;
          while (i-- &gt; 0) if (lines[i].length &gt; maxChar) {
              lines[i] = lines[i].slice(0, maxChar);
              char_removed = 1
          }
          if (char_removed || lines_removed) {
              textarea.value = lines.join('\n')
          }
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>This what I used based on few previous posts. But this code allows me to enter 'n' number of characters in 'm' number of lines. Could someone help me to write a code which takes only 30 characters and 2 lines? {suppose if the first line holds 10 characters then the next line should hold 20 characters but total number of characters should be 30 and lines to be 2.}</p>