Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Input element character limit using Jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 390
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: