www.webdeveloper.com
Results 1 to 4 of 4

Thread: Help with character counter

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    2

    Help with character counter

    Hello everyone. I wonder if anyone can help?

    I found a character counter on the web and it works if used as is:

    <script language="JavaScript">
    function countit(what){
    formcontent=what.form.charcount.value
    what.form.displaycount.value=formcontent.length
    }
    </script>



    <input type="text" name="charcount" size="40" >
    <input type="button" onClick="countit(this)" value="Count" style="font-weight:bold;">
    <input type="text" name="displaycount" size="3" style="font-weight:bold; text-align:center;">

    screenshot

    What I want to do is have the character counter on each of the 3 form input lines below instead of having it above the 3 lines (which at the moment means the customers would have to use the counter at the top and then either cut/paste or re-type the counted text into Line1, Line2 and Line 3).

    I have tried doing this but (although the button does render at the side of each field) nothing works character counting wise.

    To better understand, please add this test product to the cart and get to checkout page 2 to see what I mean.

    I would really appreciate it if someone could get this to work. Thanks.

  2. #2
    Join Date
    Jul 2007
    Posts
    386
    Here is a small script example, if you need it to be modified let me know. I did it so that the character count is automatic every time they release whatever key they press.

    JS:
    Code:
    function countChars(obj)
    {
        var counter = document.getElementById(obj.name + '_counter');
        counter.innerHTML = obj.value.length;
    }
    HTML:
    Code:
    <input type="text" name="line1" onkeyup="countChars(this)"/> Count: <span id="line1_counter"></span><br/>
    <input type="text" name="line2" onkeyup="countChars(this)"/> Count: <span id="line2_counter"></span><br/>
    <input type="text" name="line3" onkeyup="countChars(this)"/> Count: <span id="line3_counter"></span><br/>

  3. #3
    Join Date
    Oct 2012
    Posts
    2
    SparoHawk.... Mate you are a GENIUS!!!!!

    It works a treat mate!

    Thank you ever so much for this. Should you ever pass by North Devon do drop me a line, I owe you a pint.



    Quote Originally Posted by SparoHawk View Post
    Here is a small script example, if you need it to be modified let me know. I did it so that the character count is automatic every time they release whatever key they press.

    JS:
    Code:
    function countChars(obj)
    {
        var counter = document.getElementById(obj.name + '_counter');
        counter.innerHTML = obj.value.length;
    }
    HTML:
    Code:
    <input type="text" name="line1" onkeyup="countChars(this)"/> Count: <span id="line1_counter"></span><br/>
    <input type="text" name="line2" onkeyup="countChars(this)"/> Count: <span id="line2_counter"></span><br/>
    <input type="text" name="line3" onkeyup="countChars(this)"/> Count: <span id="line3_counter"></span><br/>

  4. #4
    Join Date
    Jul 2007
    Posts
    386
    Glad it was of help. If you need any other help feel free to contact me or just make another forum post.

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