"SMS Box"
Bootstrap 3.3.0 Snippet by tejlavwaladhaval

<div class="container"> <div> <br style="clear:both"> <div class="form-group col-md-4 "> <label id="messageLabel" for="message">Message </label> <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> </div> <br style="clear:both"> <div class="form-group col-md-2"> <button class="form-control input-sm btn btn-success disabled" id="btnSubmit" name="btnSubmit" type="button" style="height:35px"> Send</button> </div> </div>
.red{ color:red; }
$(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'); } }); });

Similar snippets: See More


Dieudonné Dipa Tshiauke 2015-01-20 15:46:50
    Good snippet, it really helps.
RalphAlex 2015-02-24 04:11:26
    Great one...
nowanswerme 2015-02-27 08:12:04
    good snippet but counter does not work in real time; you should use "keyup" instead of "keydown"
have a good day
Gerard Sans 2015-04-26 11:50:50
    Nice! Take care as count acts funny around the 140 value.

Commenting will be back soon.