Use the following codes to count the character dynamically enter by user in the input tag.
HTML Code:-
insert the following code in the form tag.
<input type="text" maxlength="12" />
<span>0</span>/12
jQuery Code:
insert the following code into the page head
$('input').on('keyup', function(e) {
var thisObj = $(this).next('span');
var txt = $(this).val();
var textLength = txt.length;
if(textLength>12) {
$(this).val(txt.substr(0, 12));
thisObj.html(textLength);
} else {
thisObj.html(textLength);
}
});
0 Comment(s)