www.webdeveloper.com
Results 1 to 4 of 4

Thread: Javascript- Textbox counter in increments of 100

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Javascript- Textbox counter in increments of 100

    hello,
    I have a textbox in my .net page, and totally new to java script.

    How do i get a script that will count the data being written in the text box to show increments of 100 and write the value to the bottom of the textbox.

    e.g. When u get to 100, at the bottom it says "1st hundred"

    ... and to 200 it writes "2nd hundred"

    UP to 500 ???

    Please help
    thanks

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,356

    Question Some clarification please ...

    Quote Originally Posted by mary_itohan View Post
    hello,
    I have a textbox in my .net page, and totally new to java script.

    How do i get a script that will count the data being written in the text box to show increments of 100 and write the value to the bottom of the textbox.

    e.g. When u get to 100, at the bottom it says "1st hundred"

    ... and to 200 it writes "2nd hundred"

    UP to 500 ???

    Please help
    thanks
    What data are you trying to count?
    Characters or lines or something else?
    And data is in a 'textbox' or a 'textarea'?

    Need clarification to continue.

  3. #3
    Join Date
    May 2009
    Posts
    14
    HTML Code:
    <textarea onKeyUp="keyUp(this);"></textarea>
    <input type="text" disabled id="message"/>
    
    <script type="text/javascript">
    function keyUp(textarea)
    {
      var length = textarea.value.length;
    
      if (length % 100 == 0)
        document.getElementById('message').value = length + " reached.";
    }
    </script>

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    I'm assuming you want to count characters.

    You can use a textbox or textarea.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title></title>
            <script type="text/javascript">
                var maxChars = 500;
                function countChars(str){
                    txtInpObj.value = (str.length <= maxChars)? str : str.substring(0,maxChars);
                    numCharsDivObj.innerHTML = (str.length >= 100)? numCharsDivObj.innerHTML = 'Number of hundred: '+Math.floor(str.length/100.0) : '';
                }
                window.onload=function(){
                    txtInpObj = document.getElementById('txtInp');
                    txtInpObj.onkeyup=function(){
                        countChars(this.value);
                    }
                    numCharsDivObj = document.getElementById('numCharsDiv');
                }
            </script>
        </head>
        <body>
            <div>
                <textarea id="txtInp" cols="20" rows="5"></textarea>
                <div id="numCharsDiv"></div>
            </div>
        </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles