skill-assessment-app/app/assets/javascripts/textarea-limit.js

29 lines
684 B
JavaScript
Raw Normal View History

$(document).ready(function() {
2016-08-09 11:36:52 -05:00
setTextAreaLimit();
2016-08-09 11:36:52 -05:00
function setTextAreaLimit() {
$.fn.extend({
limiter: function(limit, elem) {
$('textarea').on("keyup focus show", function() {
setCount(this, elem);
});
2016-08-09 11:36:52 -05:00
function setCount(src, elem) {
if(src !== undefined) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
chars = limit;
}
2016-08-09 11:36:52 -05:00
elem.html(limit - chars);
}
}
setCount($(this)[0], elem);
}
});
2016-08-09 11:36:52 -05:00
var elem = $(".chars span");
$('textarea').limiter(1000, elem);
}
});