CSS

Wednesday, September 26, 2012

jQuery Character Counter for Multiple Textareas

The problem I had was the user is displayed a form where there are multiple textareas that they had to type at least 140 characters in all the textareas.

Below is the jQuery code I wrote to do it:

table is the id of a table that that all the textareas are a descendent of
cntOut is the id of a span I stick the count into.

jQuery('#table').on("blur keyup", "textarea", function(e) { var cnt = 0; jQuery("textarea").each( function(o) { cnt += this.textLength; }); jQuery(PrimeFaces.escapeClientId('#cntOut')).text(cnt); });

No comments:

Post a Comment