Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    352
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Text box limiter with remaining characters

    How can I limit a text box to 50 characters and display the amount of characters left?

    Any help will be appreciated;
    Thanks,
    MW2005

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    try this:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script type="text/javascript">
    var 
    maxL=50;//nr of max permited characters
    function limit(obj){
    var 
    nrdocument.getElementById('nrc')
    var 
    = new String();
    obj.value.split('');
    for(
    i=0;i<maxL;i++){+= s[i]}
    if(
    s.length>=maxL){
    obj.value=v;
    nr.firstChild.data maxL-v.length;
    }
    else{
    nr.firstChild.data maxL-s.length;}
    }
    onload=function(){
    document.getElementById('nrc').firstChild.data=maxL;
    }
    </script>
    </head>
    <body>
    <input type="text" onkeyup="limit(this)"><span id="nrc">&nbsp;</span>&nbsp;characters left
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Posts
    352
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks


  •  

    Posting Permissions

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