jQuery Max Length Reference

A jQuery plugin that applies a maximum length to a textarea.

This page provides a documentation reference for working with the plugin v1.0.3. See a demonstration of the max length plugin and download the code from there. Or see a minimal page that you could use as a basis for your own investigations.

Instance Settings

Customise each targetted input field with the settings below (all are optional):

$(selector).maxlength({max: 400});
NameTypeDefaultComments
maxnumber200 The maximum number of characters allowed in the textarea.
truncatebooleantrue Set to true to truncate any characters after the maximum allowed, or false to only highlight the overflow. The textarea and the feedback element are marked with classes to indicate their status: maxlength-full when at or past the maximum number of characters and maxlength-overflow when past that maximum.

Since 1.0.2.
showFeedbackboolean or stringtrue Set to true to show a countdown of characters used/remaining. Set to 'active' to only show the feedback when the textarea is hovered or focussed. Otherwise no feedback is shown. See truncate for classes applied to the textarea and feedback element to indicate their status.

Since 1.0.2 - 'active' added.
feedbackTarget string or element or jQuery or functionnull Redirect the feedback to another element on the page - it only has effect if showFeedback is not false. Provide either the jQuery selector, the DOM element itself, the element in a jQuery wrapper, or a function that returns the element within a jQuery wrapper. Within any callback function, the this value is the current textarea.

Since 1.0.2.
feedbackTextstring '{r} characters remaining ({m} maximum)' The text to display for feedback to the user. Include substitution points within the text: '{r}' for the number of characters remaining, '{c}' for the number of characters entered, and/or '{m}' for the maximum number of characters allowed.
overflowTextstring '{o} characters too many ({m} maximum)' The text to display for feedback to the user when there are more characters in the field than the allowed maximum (see truncate). Include substitution points within the text: '{o}' for the number of characters past the maximum, '{c}' for the number of characters entered, and/or '{m}' for the maximum number of characters allowed.

Since 1.0.2.

Functions

SignatureReturnsComments
$.maxlength.setDefaults(settings)MaxLength object Update the default instance settings to use with all max length instances.
$(selector).maxlength('change', settings)jQuery object Update the settings for the max length instance attached to the given textarea(s).
$(selector).maxlength('settings')object Retrieve the current settings for the first max length instance attached to the given textarea(s).

Since 1.0.1.
$(selector).maxlength('destroy')jQuery object Remove the max length functionality from the given textarea(s).

Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.


Valid HTML 4.01 Strict