Displaying the Number of Words Typed Into an HTML Form
Field
By
William
Bontrager
While programming Master Reciprocal
Links Pro (which should be ready for release soon), I needed to limit and
display the number of words in a link request form field.
I did a quick search on the Internet to see how others might have done it
and found only examples of how to limit and display the number of characters.
I needed to do it with words.
So I made one without the time saving benefit of example.
This article and accompanying demonstration at URL
http://willmaster.com/a/24h/pl.pl?art245 show you how
do to it, too. Copy and paste and specify your preferences.
The JavaScript can limit the number of words, the number of characters, or
both.
And it can display the number already typed, the number still available,
or both.
The JavaScript works with you to display only what you want to display. It
has eight places where you can specify your preferences.
The demonstration form and JavaScript are commented for easy integration
into your custom form.
Because this is JavaScript, it can be turned off and the limits bypassed.
But then your form handling CGI program should catch the attempt.
There are several reasons I wanted to display the number of words and monitor
the limit with JavaScript:
With JavaScript, the user can be constantly apprised about how many
words/characters have been typed and how many are still allowed.
This is much better than saying, "Describe your site with 50 words or less"
and then leaving it up to the user to do the counting.
Although Master Reciprocal Links Pro will catch attempts to bypass the site
description word count limitations the webmaster has specified, it is easier
and less frustrating for the user to receive JavaScript error messages than
to submit the form and only then receive CGI program error messages.
That's because JavaScript can have a near immediate response. CGI requires
submitting the form and the program sending an error page back which, depending
on user connection speed and domain server speed, might be several long seconds.
I like JavaScript and I like to make things user-friendly.
When you need to limit the amount of text a user may type into a form and
display the count for the user,
http://willmaster.com/a/24h/pl.pl?art245 is where to find
a working example.
Will Bontrager
Copyright 2004 Bontrager Connection, LLC
About the Author:
|
|