Limit Word Count of A Textfield in JQuery -


I am modifying some jquery code to limit the word count of a textfield but I can not understand that How to value Here's the code:

  & lt; Script & gt; Var $ limitWords = 20; Var $ wordCount = $ ('# count'). Val (); $ (Document) .ready (function () {$ ("# edit-field-message-0-value"). Keyup (function () {$ ('# count'). Html ($ ('# edit-field ($ WordCount & gt; $ limitwords) {$ ('# edit) AddClass (' error ');} and {$ (' # edit-field-message-0-value '). AddClass (' not-error ' );}}}}}; & Lt; / script & gt;  

Specifically, to return the current value, should be equal to "$ wordCount"?

I think it should be easy, but I do not think so

any thoughts?

Thank you, Scott

I did not understand enough $ wordCount variable Believe that you can try to do the following:

  $ ("# edit-field-message-0-value"). Key (function () {var $ this = $ (This); var wordcount = $ this.val (). Split (/ \ b [\ s, \ .---;; * /) Length; if (wordpress> $ limit words) {$ this AddClass ('Error');} and {$ this.addClass ('No-Error');}});  

I'm also guessing that you can store the current calculation Want:

  $ ("# edit-field-message-0-value") .keyup (function () {var $ this = $ (this); Var wordcount = $ this.val (). Split (/ \ b [\ s, \ .-:;] * /) Length; If (wordcount & quot; $ limitWords) {$ ('# count') Html ($ limitWords); $ This.addClass ('Error');} and {$ ('# Count'). Html (wordcount); $ This.addClass ('no-error');}});  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -