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 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multi-Field Character Count Total

    The following script basically counts the characters in a text area and shows the number of characters on the fly. I need to have the combined total of four text areas limited to an amount and ideally would like it to display the count as this script does. For example: a contact form that would contain a "Name", "E-Mail", "Phone" and "Message" field that when combined can only reach an X number of characters. I apologize in advance - I am new.

    Thanks!

    <script language = "Javascript">
    /**
    * DHTML textbox character counter (IE4+) script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
    */

    function taLimit() {
    var taObj=event.srcElement;
    if (taObj.value.length==taObj.maxLength*1) return false;
    }

    function taCount(visCnt) {
    var taObj=event.srcElement;
    if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
    if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
    }
    </script>
    Last edited by lipak; 06-04-2004 at 03:28 PM.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    FWIW: The script you posted is IE only.
    Are you really not interested in cross-browser compatability?

    But to answer your question. Set a global variable to increment with your taObj.value.length and use that value to reach your maximum character limit.

    The question is. What happens if a user goes over the character limit? Which field will it effect? I would assume the message, but we would need more information. Particularly some code...

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your response is greatly appreciated!

    Forgive me for lack of information. I am definitely interested in cross browser compatibility, but I am new and don't know what I need to add to make that happen. It would be fine with the character limit showing up in the Message text area since it will be the final area that is filled out (Potentially flawed? Perhaps, but it would do for now). Unfortunately I also do not know how to set a global variable. Any additional help is appreciated. Here is the HTML code that goes along with the previous posted script:

    <font> Maximum Number of characters for this text box is 255.<br>
    <TEXTAREA onkeypress="return taLimit()" onkeyup="return taCount(myCounter)"
    name=Description rows=7 wrap=physical cols=40 maxLength="255"></TEXTAREA>
    <br><br>
    You have <B><SPAN id=myCounter>255</SPAN></B> characters remaining
    for your description...</font>

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not inclined to write a complete form just to demonstrate a few lines of code. If you post your entire form, I will look into writing a cross browser script.

  • #5
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for you assistance, I'm sorry I didn't post more code. I didn't realize you wanted the whole form. I have attached the form with the counter script.
    Attached Files Attached Files

  • #6
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi everybody.

    If anyone else wants to give this a go, please feel free - it would be greatly appreciated.

  • #7
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is a link to a form that basically does what I want it to (counts the total characters of specified fields and limits them to a certain amount - result is reflected with the running total)

    http://www.txt.bellmobility.ca/bmc/en/


  •  

    Posting Permissions

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