Categories: All Free JavaScripts/ Applets Tutorials References

Home / Free JavaScripts / Forms / Here

Cut & Paste Enforce max # of characters in form element

Credit: JavaScript Kit

Description: Put a cap on the amount of characters certain form fields of your form accept, by using this useful script. Once the limit has been reached, typing within the field in question has no effect.

Example:

Enter your hobbies (<50 characters)

Enter your area code (3 characters) and phone number:

-

Directions

Step 1: Add the following script to the <HEAD> section of your page:

Step 2: Then, add the below sample form to your <BODY>:

As illustrated inside the form, to enforce characters inside a form element, apply the code:

onkeypress="return enforcechar(this, 10)"

inside it, changing 10 to the maximum # of characters the element(s) is to accept. Applicable elements are TEXTAREA or <INPUT>.


JavaScript Tools:
Site Info

CopyRight © 1998-2008 JavaScript Kit. NO PART may be reproduced without author's permission.