Bjorn Wijers schrieb: > Hi everybody, > > I recently made my first jquery plugin called textlimiter. It allows you > to limit a textarea in the same way as an input field using the > maxlength attribute. As an added bonus the plugin adds a counter which > keeps track of the amount of character left before hitting the limit set > in the maxlength attribute. > > As far as I know there is no other plugin (yet?) providing this > functionality and I would like to ask all of you to test it on your > setup to see if it works for your system. So far I have tested it on > Firefox 2, Opera 9.10 and Safari 2.04 and this works as expected. > > You can check this plugin on: > > http://www.burobjorn.nl/code/textlimiter/ > > > TODO > - allow counter to count up instead of counting down using a parameter. > - use a parameter to set the class when hitting the limit? > - documentation for non-programmers > I like it!
Some things I noticed: - I manged to get a -1 count on the second textarea, mostly by typing wildly in it - if(typeof(nr) == "undefined") { nr = 0; } <- that line seems to define a global variable if it isn't set yet, why not just using var nr = 0; ? - I'd like to be able to specify the maxlength via a plugin option instead of the attribute - there is no need to set the "relatedElement" as an expando property, you can just use a closure to access it from inside the keyup handler, eg. var related = ...; $(...).keyup(function() { /* do something with related */ }); - you don't need that ID on the counter either, instead create it as: var counter = $(html_counter).insertBefore(this); - then you can use "counter" instead of searching for the id and saving it as relatedElement Hope that helps. -- Jörn Zaefferer http://bassistance.de _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/