Word Counter Script

Word Counter Javascript less CSS Supports all frameworks.


by : @radhikabajaj - snippets

<-----------------------body------------------/>

 <textarea class="form-control input-sm " type="textarea" id="message" placeholder="Message" maxlength="140" rows="7"></textarea>
  <span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>               

<-----------------------CSS------------------/>


.red{
    color:red;
    }
 

<-----------------------Head------------------/>

<script>

$(document).ready(function(){ 
    $('#characterLeft').text('140 characters left');
    $('#message').keyup(function () {
        var max = 140;
        var len = $(this).val().length;
        if (len >= max) {
            $('#characterLeft').text('You have reached the limit');
            $('#characterLeft').addClass('red');
            $('#btnSubmit').addClass('disabled');            
        } 
        else {
            var ch = max - len;
            $('#characterLeft').text(ch + ' characters left');
            $('#btnSubmit').removeClass('disabled');
            $('#characterLeft').removeClass('red');            
        }
    });    
});
 

</script>

2020-05-14 17:26:38