Solved

character count as I am typing into an input textbox

Posted on 2010-08-12
8
764 Views
Last Modified: 2012-05-10
character count as I am typing into an input textbox
0
Comment
Question by:rgb192
8 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33422458
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 33422459
0
 
LVL 29

Expert Comment

by:Badotz
ID: 33423815
Something along these lines (untested, sorry):

<script type="text/javascript">

function io_count(src, tgt) {
    if (src.nodeName && src.nodeName === "INPUT") {
        if (typeof tgt === "string") {
            tgt = document.getElementById(tgt);
        }
        tgt.value = src.length;
        return false;
    }
    return true;
}
</script>
...
<body>
<input id="txt_test1" onchange="return io_count(this, 'div_test1');" value="" />
<div id="div_test1"></div>
<input id="txt_test2" onchange="return io_count(this, 'div_test2');" value="" />
<div id="div_test2"></div>
...
</body>

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 33424631
Try this, is tested.

Bye
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  <script>
    function changeContent(){
        var txt = document.getElementById('testtext').value;
        document.getElementById('dest').innerHTML = txt;
    }
    function countChars(){
        var len = document.getElementById('testtext').value.length;
        document.getElementById('dest').innerHTML = len;
    }
</script>
</head>
  <body>
    <form name='test' action='test.html' method='post'>
    <input type="text" id="testtext" name="testtext" onkeyup="countChars();">
    </form>
    <table>
    <tr>
    <td id='dest'></td>
    </tr>
    </table>
  </body>
</html>

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33424772
Sorry, I forgot a little trick. Add this function within <script> tags:

    function emptyText(){
      document.getElementById('testtext').value = '';  
    }

and add this to the <body tag:

<body onload="emptyText();">

This ensure that refreshing the page the text box is empty and the count begin from 0.

Bye
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33429739
or

window.onload=function() {
 countChars();
    }

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33436637
Still need you assistance with this?
0
 

Author Closing Comment

by:rgb192
ID: 33436803
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question