jQuery word Counting & Limit Characters in Textarea

A simple jQuery word counting and characters limit plugin for textarea / text input field. The plugin show the character left (or entered chars) on the top of the input field.

You can easily integrate this lightweight plugin in your projects. The characters counting stats can be inserted top or bottom of input.

Plugin Overview

Plugin: Count Chars
Author: Wayne Boka
Licence: MIT Licence
Published: January 19, 2024
Repository: Fork on GitHub
Dependencies: jQuery 1.3.1 or Latest version
File Type: zip archive (HTML, CSS & JavaScript )
Package Size: 7.05 KB

How to Make jQuery word Counting & Limit Characters

1. Load the jQuery and count chars‘s JavaScript file into your webpage.

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<!-- Count Chars -->
<script type="text/javascript" src="/src/jquery.count-chars.js"></script>

2. After that, create HTML textarea or input element to count entered characters.

<h2> Textarea Chars Count</h2>
<textarea class="notes" maxlength="4000"></textarea>

<h2> Input Chars Count</h2>
<input type="text" class="notes" maxlength="50" />

Tip: Use the maxlength attribute to set the characters limit in input.

3. Initialize the plugin in jQuery document ready function.

$(document).ready(function() {

   $("textarea, input").countChars();

});

4. The basic CSS styles for textbox (input & textarea).

textarea {
	display: block;
	width: 100%;
}

h2, div {
	color: #FFFFFF;
}

.bucket {
	background: #0769AD;
	margin: 5px;
	padding: 10px;
}

4. Set the position for counting stats. Available option are: “before” or “after”.

$("textarea, input").countChars({
   position: "before",
});

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X