View your Shopping CartFrequently Asked QuestionsEmail Us
Home | About Us | Contact Us
SmartWebby.com provides best web design & web programming services globally
We specialize in Rapid Web Design, ASP.net, ASP and PHP web programmingBest Web Design, Best Web Programming, Global Service Provider - Dependable Professionals to build your website right!

Text Box Characters Counter (IE, Opera & Safari)

In forms when using text boxes or text areas with limited character length (usually needed for forms that submit data to a database) it is always a good idea to tell the user how many characters they have remaining. This javascript snippet is especially useful for textarea fields since they can't be assigned a text limit in HTML but can be restricted using this code.

The following example shows how you can do this. This is a very simple and cute idea to help the user know exactly how many characters can be typed further. Do these small add-ons to your forms and they will look really professional. We recommend using this counter inside CMS solutions and custom built Admin Panels where your clients/visitors can be instructed to use IE/Opera or Safari. Alternately, to make the code cross browser compatible, you can make the span element into an input box with no background (so it looks like a span tag) and then it would work with the same code in Firefox and Netscape as well.

Example

Example of displaying how many characters remain while filling data into a text box field


    You have 255 characters remaining for your description...


View Explanation of the Code

Cut and Paste Code

Cut 'n' paste code for the above Example

JavaScript Code
HTML Code
Note: You need to change the name of the myCounter field if you use multiple text boxes and also change the reference to it in the event onKeyUp for the respective boxes.

Explanation of the Code

The JavaScript code has two main functions: