By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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:

<body
onload="showRemaining(document.forms['myForm'].elements['myInput']);">

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

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:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* 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

P: n/a
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.