Web Application Development Advice & How To
Active Server Pages Development Advice & How To

Shining Star Services LLC
Shining Star Services
ASP.net Articles
HTML Tutorial
Auto-select an Element from a Menu or Scrolling List & Save Keystrokes!
ASP Driven DHTML Slider Menus REVISITED One Year Later! Part II
ASP Driven DHTML Slider Menus
ASP Driven HTML Outlines
Reusing Code with ASP Include Files and Subroutines
Hacker Query Check
.htr IIS Security Issue
Databases, Cookies
Functions to Open a Database Connection and Record Set
Setting Up and Using OraSession to Manage Your Oracle Database Objects
Storing Non-Durable Data for Cookie-less Sessions
Smart Popups
Javascript: Validate Numeric Fields
Javascript Confirm Form Submission
Javascript Dynamic Text Area Counter
Javascript: Check All and Uncheck All Check Boxes
Javascript Field Validations -- Client Side Scripting
Tree Select Demo
Adobe Extension Manager
Scandisk & Defrag Pointers
Standards & Style
Setting Up Your Own ASP Development Templates
Creating a Project Template for Estimations of Time, Tasks, and Resources
To Host or Not To Host
ASP Naming Conventions
HTML Naming Conventions & Visual Interdev HTML Generation
Working with and in spite of the Visual Interdev Design Mode
Commenting Your ASP Source Code
Reader Letters

Articles Home

Shining Star Services

Javascript Dynamic Text Area Counter
By Nannette Thacker - 05/19/2000

I found this cool text area counter, Limit Text Area, written by Ronnie T. Moore, on The JavaScript Source. Unfortunately, it hard-coded the name of the form element inside the function, which would require I create a new function for every text area that needed to track character counts.

So I rewrote the function, passing the name of the form text area element, the field to display the counter, and the maximum number of characters allowed for that text area.

One Function to Count and Limit Multiple Form Text Areas

characters left

characters left

Here is the code for the form:

<form name="myForm"
<b>One Function to Count and Limit Multiple Form Text Areas</b><br>
<textarea name="message1" wrap="physical" cols="28" rows="5"
<input readonly type="text" name="remLen1" size="3" maxlength="3" value="125">
characters left
<textarea name="message2" wrap="physical" cols="28" rows="5"
<input readonly type="text" name="remLen2" size="3" maxlength="3" value="125">
characters left
<input type="Submit" name="Submit" value="Submit">

Here is the javascript function:

<!-- Dynamic Version by: Nannette Thacker -->
<!-- http://www.shiningstar.net -->
<!-- Original by :  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!-- Begin
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
cntfield.value = maxlimit - field.value.length;
//  End -->

Check out The JavaScript Source for some of the BEST javascripts!


ShiningStar.net | ShiningStarSingles.com | Christian911.com