title: Count carriage returns in javascript
body: <p>I'm running the following code to set a limit on characters in a textarea:</p>
  
  <pre><code>(function($){ 
   $.fn.extend({  
       limit: function(limit,element) {
  
          var interval, f;
          var self = $(this);
  
          $(this).focus(function(){
              interval = window.setInterval(substring,100);
          });
  
          $(this).blur(function(){
              clearInterval(interval);
              substring();
          });
  
          substringFunction = "function substring(){ var val = $(self).val();var length = val.length + carriages;if(length &gt; limit){$(self).val($(self).val().substring(0,limit));}";
          if(typeof element != 'undefined')
              substringFunction += "if($(element).html() != limit-length){$(element).html((limit-length&lt;=0)?'0':limit-length);}"
  
          substringFunction += "}";
  
          eval(substringFunction);
  
  
  
          substring();
  
      } 
  }); 
  })(jQuery);
  </code></pre>
  
  <p>The area my users are entering text into can fit a maximum of 1500 characters.  The problem is that it can only fit a maximum of 10 lines.  If they enter 25 characters on one line before entering a carriage return, the characters total needs to be at 150, not 26.</p>
  
  <p>How can I accomplish this?</p>