Renate: Zeilenumbrüche bei Char count in einer Textarea filtern

Beitrag lesen

Guten Morgen,

ich habe mir aus dem Netz ein Script geladen um auf meiner Homepage die Eingabe in ein Formular zu begrenzen. Natürlich prüfe ich das auch noch mit PHP.
Leider wird mir durch die verschiedenen LineBreaks (\n, \r) in den unterschiedlichen Browsern eine unterschiedliche Anzahl Zeichen angezeigt.
Wie kann ich dies in dem folgenden Script berücksichtigen?

Danke für Hilfe

R.

  
(function($) {  
  
	$.fn.charCount = function(options){  
	  
		// default configuration properties  
		var defaults = {	  
			css: 'counter',  
			counterElement: 'div',  
			cssWarning: 'warning',  
			cssExceeded: 'exceeded',  
			counterText: 'Verfügbare Zeichen: '  
		};  
			  
		var options = $.extend(defaults, options);  
		  
		function calculate(obj){  
			var count = $(obj).val().length;  
			var available = options.allowed - count;  
			if(available <= options.warning && available >= 0){  
				$(obj).next().addClass(options.cssWarning);  
			} else {  
				$(obj).next().removeClass(options.cssWarning);  
			}  
			if(available < 0){  
				$(obj).next().addClass(options.cssExceeded);  
			} else {  
				$(obj).next().removeClass(options.cssExceeded);  
			}  
			$(obj).next().html(options.counterText + available);  
			};  
				  
		this.each(function() {  			  
			$(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');  
			calculate(this);  
			$(this).keyup(function(){calculate(this)});  
			$(this).change(function(){calculate(this)});  
		});  
	  
	};  
  
})(jQuery);  
  
  
$(document).ready(function(){  
		$("#nachricht").charCount({  
			allowed: 200,		  
			warning: 20  
		});	  
	});