A jQuery plugin that applies a maximum length to a textarea.
The current version is 1.0.0 and is available under the GPL and MIT licences. For more detail see the documentation reference page.
The max length functionality can easily be added to a textarea
with appropriate default settings.
You can also remove the max length functionality if it is no longer required.
Default max length:
$('#defaultLength').maxlength();
$('#removeLength').toggle(function() {
$(this).text('Re-attach');
$('#defaultLength').maxlength('destroy');
},
function() {
$(this).text('Remove');
$('#defaultLength').maxlength();
}
);
You can override the defaults globally as shown below:
$.maxlength.setDefaults({showFeedback: true});
Processed fields are marked with a class of hasMaxLength
and are not re-processed if targetted a second time.
Customise the max length functionality through additional settings.
Different length:
$('#otherLength').maxlength({max: 300});
No feedback shown:
$('#noShowLength').maxlength({showFeedback: false});
Custom feedback:
$('#feedbackLength').maxlength({feedbackText: 'Used {c} of {m}'});
#feedbackLength + .maxlength-feedback { clear: both; margin-left: 20em; }
This tab highlights examples of this plugin in use "in the wild".
None as yet.
To add another example, please contact me (kbwood{at}iinet.com.au) and provide the plugin name, the URL of your site, its title, and a short description of its purpose and where/how the plugin is used.
A full list of all possible settings is shown below. Note that not all would apply in all cases. For more detail see the documentation reference page.
$(selector).maxlength({
length: 200, // Maximum length
showFeedback: true, // True to show user feedback
feedbackText: '{r} characters remaining ({m} maximum)'
// Display text for feedback message, use {r} for remaining characters,
// {c} for characters entered, {m} for maximum
});
$.maxlength.setDefaults(settings) // Change settings for all instances
$(selector).maxlength('change', settings) // Change the instance settings
$(selector).maxlength('destroy') // Remove the max length functionality
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script><style type="text/css">@import "jquery.maxlength.css";</style>
<script type="text/javascript" src="jquery.maxlength.js"></script>
Alternately, you can use the packed version
jquery.maxlength.pack.js (??K vs ??K), or the minified version
jquery.maxlength.min.js (??K, ??K when zipped).$(selector).maxlength();
You can include custom settings as part of this process.
$(selector).maxlength({max: 300});For more detail see the documentation reference page.
None as yet.
Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | ?? ??? 2009 |
|