Re: default fill friendly form character countdown script -- how to?
Matthew wrote:
[color=blue]
> Is there a javascript or alternative default fill friendly way for
> counting down the remaining characters left in a form box?[/color]
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(f ormElement) {
var theForm = formElement.for m;
var remainingDispla y = formElement.nam e + 'Remaining';
theForm.element s[remainingDispla y].value = formElement.max Length -
formElement.val ue.length;
}
</script>
<form name="myForm">
<input type="text" name="myInput" maxlength="20"
onkeyup="showRe maining(this);" >
<input type="text" name="myInputRe maining" 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>.m axLength 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 <gwagner@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
Comment