Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7971351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:37:08+00:00 2026-06-04T07:37:08+00:00

I found the solution below to a simple textbox character counter (like Twitter). Rather

  • 0

I found the solution below to a simple textbox character counter (like Twitter).

Rather than use a single textbox, I’ve been trying to amend the code to accommodate multiple text inputs without success.

The reason is because I want to validate a URL and text before sending them as the same tweet.

Can anybody point me in the right direction?

<span class="counter"></span>
<input type="text" name="field1" id="field1" class="word_count" />
<input type="text" name="field2" id="field2" class="word_count" />

js:

$(document).ready(function () {
    $('.word_count').each(function () {
        var $this = $(this);
        var counter = $this.parent().find('.counter');
        var maxlength = $this.attr('maxlength');

        counter.text('Only ' + maxlength + ' characters allowed');

        $this.bind('input keyup keydown', function () {
            var value = $this.val();

            if (value.length > 0) {
                counter.text((maxlength - $this.val().length) + ' characters left');
            } else {
                counter.text('Only ' + maxlength + ' characters allowed');
            }
        });
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:37:10+00:00Added an answer on June 4, 2026 at 7:37 am

    First of all here’s the fiddle. http://jsfiddle.net/bczengel/tsbfU/

    Here were the issues.

    1. The code is looking for a maxLength attribute on the input fields that was not present. Hence the NaN messages.
    2. If your using the latest version of jQuery you should be using the .on() method. It has a few other features over bind but basically its the newer method.
    3. You don’t need to iterate over all of the inputs. jQuery will bind your events to all elements it finds in its result set. Basically you were creating a new function for each input when only one was necessary.
    4. I added focus to the list of events so that the counter was updated when you entered an input. You may want to add a separate blur event handler to hide the counter when no input is focused.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: found a solution, see below. I'm trying to get a clicked tile div
Update Solution Found See Bottom of post if interested Seems simple enough and for
I am trying to write an ultra simple solution to load a bunch of
EDIT: I found the solution, see below My first post on StackOverFlow. However I
Did some search online, found simple 'tutorials' to use named pipes. However when I
Im trying to achieve an inner-shadow effect on a simple box, something like: alt
UPDATE: I actually found the solution myself, see below. In R I want to
Need help! I've been looking for a solution for this seemingly simple task but
EDIT - FOUND A EASY 5-10 LINE SOLUTION!!! See MY OWN ANSWER BELOW!!! YAY!!!!!!!!!
I have very obvious problem, but still did not found solution to it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.