Bind Text Counter
function TextCounter (CountLimit, Elem, CounterElem) {
var elem = $("#" + Elem);var Counterelem = $("#" + CounterElem);
elem.bind("keyup focus", function () {
setCount(elem[0], Counterelem,CountLimit);
});
setCount(elem[0], Counterelem,CountLimit);
}
function setCount (src, elem,limit) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
chars = limit;
}
elem.html(limit - chars);
}
Calling Method
TextCounter(5,'samp','counter');
0 comments:
Post a Comment