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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew

    #1

    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?
  • Grant Wagner

    #2
    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:

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

    <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:
    *


    * 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


    Comment

    • Matthew

      #3
      Re: default fill friendly form character countdown script -- how to?

      Ah, that's great... exactly what I was looking for. Thanks! :)

      Comment

      Working...