"Message box with counter"
Bootstrap 3.0.0 Snippet by jstrangio

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<div class="col-sm-4 col-md-4">
<div class="panel panel-default">
<div class="panel-body">
<form accept-charset="UTF-8" action="" method="POST">
<textarea class="form-control counted" name="message" placeholder="Type in your message" rows="5" style="margin-bottom:10px;"></textarea>
<h6 class="pull-right" id="counter">320 characters remaining</h6>
<button class="btn btn-info" type="submit">Post New Message</button>
</form>
</div>
</div>
</div>
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
body{padding-top:20px;}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
*
* jquery.charcounter.js version 1.2
* requires jQuery version 1.2 or higher
* Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function($) {
/**
* attaches a character counter to each textarea element in the jQuery object
* usage: $("#myTextArea").charCounter(max, settings);
*/
$.fn.charCounter = function (max, settings) {
max = max || 100;
settings = $.extend({
container: "<span></span>",
classname: "charcounter",
format: "(%1 characters remaining)",
pulse: true,
delay: 0
}, settings);
var p, timeout;
function count(el, container) {
el = $(el);
if (el.val().length > max) {
el.val(el.val().substring(0, max));
if (settings.pulse && !p) {
pulse(container, true);
};
};
if (settings.delay > 0) {
if (timeout) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: