display number of characters in textarea box

Discussion in 'Javascript' started by tony wong, Sep 11, 2005.

  1. tony wong

    tony wong Guest

    i wish to count number of characters in textarea box during typing in and
    display it somewhere in html page. so the number will increase during
    writing.

    is it possible to do it by javascript?

    Thanks a lot.

    Tony
     
    tony wong, Sep 11, 2005
    #1
    1. Advertising

  2. tony wong

    Randy Webb Guest

    Zoe Brown said the following on 9/11/2005 2:31 PM:
    > "tony wong" <> wrote in message
    > news:43244931$1@127.0.0.1...
    >
    >>i wish to count number of characters in textarea box during typing in and
    >>display it somewhere in html page. so the number will increase during
    >>writing.
    >>
    >>is it possible to do it by javascript?

    >
    >
    > create an event for the onchange value of the textarea, get the value of the
    > textarea and then count the chars.


    Use the onkeyup instead, and after onkeyup you check the character
    count. onchange will only fire *after* the textarea has lost focus.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Sep 11, 2005
    #2
    1. Advertising

  3. tony wong

    mscir Guest

    mscir, Sep 11, 2005
    #3
  4. tony wong

    McKirahan Guest

    "Randy Webb" <> wrote in message
    news:...
    > Zoe Brown said the following on 9/11/2005 2:31 PM:
    > > "tony wong" <> wrote in message
    > > news:43244931$1@127.0.0.1...
    > >
    > >>i wish to count number of characters in textarea box during typing in

    and
    > >>display it somewhere in html page. so the number will increase during
    > >>writing.
    > >>
    > >>is it possible to do it by javascript?

    > >
    > >
    > > create an event for the onchange value of the textarea, get the value of

    the
    > > textarea and then count the chars.

    >
    > Use the onkeyup instead, and after onkeyup you check the character
    > count. onchange will only fire *after* the textarea has lost focus.
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly


    <html>
    <head>
    <title>count.htm</title>
    <script type="text/javascript">
    function count(that) {
    window.status = that.value.length;
    }
    </script>
    </head>
    <body>
    <form>
    <textarea name="text" cols="50" rows="10" onkeyup="count(this)"></textarea>
    </form>
    </body>
    </html>
     
    McKirahan, Sep 12, 2005
    #4
  5. tony wong

    Randy Webb Guest

    McKirahan said the following on 9/11/2005 8:21 PM:
    > "Randy Webb" <> wrote in message
    > news:...
    >
    >>Zoe Brown said the following on 9/11/2005 2:31 PM:
    >>
    >>>"tony wong" <> wrote in message
    >>>news:43244931$1@127.0.0.1...
    >>>
    >>>
    >>>>i wish to count number of characters in textarea box during typing in

    >
    > and
    >
    >>>>display it somewhere in html page. so the number will increase during
    >>>>writing.
    >>>>
    >>>>is it possible to do it by javascript?
    >>>
    >>>
    >>>create an event for the onchange value of the textarea, get the value of

    >
    > the
    >
    >>>textarea and then count the chars.

    >>
    >>Use the onkeyup instead, and after onkeyup you check the character
    >>count. onchange will only fire *after* the textarea has lost focus.
    >>
    >>--
    >>Randy
    >>comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

    >
    >
    > <html>
    > <head>
    > <title>count.htm</title>
    > <script type="text/javascript">
    > function count(that) {
    > window.status = that.value.length;


    Why the status bar? That will utltimately fail in Mozilla based browsers
    that have the ability to script the status bar disabled.


    And please fix your OE so that it does not quote signatures.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Sep 12, 2005
    #5
  6. tony wong

    ASM Guest

    Zoe Brown wrote:
    > "tony wong" <> wrote in message
    > news:43244931$1@127.0.0.1...
    >
    >>i wish to count number of characters in textarea box during typing in and
    >>display it somewhere in html page. so the number will increase during
    >>writing.
    >>
    >>is it possible to do it by javascript?

    >
    >
    > create an event for the onchange value


    Not at all !
    use : onkeyup

    > of the textarea, get the value of the
    > textarea and then count the chars.


    <textarea
    onkeyup="document.getElementById('count').innerHTML=this.value.length;">
    </textarea>
    <p id="count">


    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, Sep 12, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clintonG
    Replies:
    4
    Views:
    551
    clintonG
    Oct 17, 2005
  2. Augustus
    Replies:
    1
    Views:
    362
    Ken Schaefer
    Sep 10, 2003
  3. Ken Fine
    Replies:
    2
    Views:
    199
    Ken Fine
    Feb 5, 2004
  4. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    337
    Anthony Jones
    Feb 5, 2006
  5. Replies:
    1
    Views:
    319
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page