468,140 Members | 1,437 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

default fill friendly form character countdown script -- how to?

Is there a javascript or alternative default fill friendly way for
counting down the remaining characters left in a form box?
Jul 20 '05 #1
2 4571
Matthew wrote:
Is there a javascript or alternative default fill friendly way for
counting down the remaining characters left in a form box?

I'm not sure what you mean, I'm assuming you want to provide the user
with some feedback as to how many characters they can still enter in
an <input type="text" ...>? If so:


<script type="text/javascript">
function showRemaining(formElement) {
var theForm = formElement.form;
var remainingDisplay = formElement.name + 'Remaining';
theForm.elements[remainingDisplay].value = formElement.maxLength -
<form name="myForm">
<input type="text" name="myInput" maxlength="20"
<input type="text" name="myInputRemaining" size="2" readonly>

Works in IE 6.0SP1 (will probably work as far back as IE4, but I can't
test that), Mozilla/Firebird/Netscape 7 and Opera 7.23.

Won't work in Netscape 4.x for a variety of reasons, not the least of
which is that Netscape 4.x doesn't return <formElement>.maxLength when
asked for that value.

Also, if the user presses and holds a single key, you don't get an
update until they release the key. I'm not sure there is *anything*
that can be done about that, because AFAIK, even the onkeypress event
doesn't fire repeatedly when a key is pressed and held down.

| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:

* Internet Explorer DOM Reference available at:

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2
Ah, that's great... exactly what I was looking for. Thanks! :)
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Greg A | last post: by
5 posts views Thread by Matt Stanley | last post: by
88 posts views Thread by Mike | last post: by
2 posts views Thread by Floortje | last post: by
8 posts views Thread by Michael | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.