Matthew said:
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 <
[email protected]>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html