
Home
Form effects
Here
|
Categories
Partners
DaniWeb is an exciting community for web developers, Internet marketers, and technology enthusiasts.
Other Sections
Compatibility
|
|
NS6+ IE5+ Opera 7+
Form field Limiter Author:
Note: Updated Dec 7th, 04'. Script now supports input either by form element's name or ID. Description: Want to limit the amount of text a user can enter in particular INPUT or TEXTAREA elements? Well, this script enables not only that, but displays in real time the number of characters remaining. An extremely practical and useful script that functions in both IE4+ and NS6+! Demo: Try typing in the below form. Step 1: Add the below script to the <HEAD> section of your page: Step 2: Insert the below sample form onto your page, which also demonstrates how to associate the script with your own form: As shown, enabling the script on a particular form element is a simple process: <input type="text" name="george"><br>
<script>
displaylimit("document.sampleform.george","",8)
</script>
Simply add the code in blue directly beneath the form element in question. Function displaylimit() within accepts the following three parameter: displaylimit("document.formname.elementname", "elementID", "characterslimit")
* Useful informationThe 1) and 2) parameters of displaylimit() above allow you to reference your form element via two different ways- either using its name or ID. This is extremely useful if your form elements do not contain unique names, in which using their IDs is the only way to reference each one. For example, in many PHP forms, the names of form elements need to be arrays, such as: <input type="text" name="survey[]"> <input type="text" name="survey[]"> <input type="text" name="survey[]">
Since "survey[]" is a
shared and non unique name, passing it in as the first parameter of the
function will not work. The solution is simply to assign each textbox with
a unique ID attribute, and pass that value in instead for each textbox.
|