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 8139561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:51:58+00:00 2026-06-06T11:51:58+00:00

I am creating a website with four textarea forms. Each form has a word

  • 0

I am creating a website with four textarea forms. Each form has a word limit.

  • textarea1: 250 word limit
  • textarea2: 500 word limit
  • textarea3: 500 word limit
  • textarea4: 250 word limit

I have tried using existing examples that I have found when trying to fix this problem but nothing seems to work.

   <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
var maxwords = 250;
//
function check_length(obj, cnt, rem)
{
    var ary = obj.value.split(" "); // doubled spaces will throw this off
    var len = ary.length;
    cnt.innerHTML = len;
    rem.innerHTML = maxwords - len;
    if (len > maxwords) {
        alert("Message in '" + obj.name + "' limited to " + maxwords + " words.");
        ary = ary.slice(0,maxwords-1);
        obj.value = ary.join(" "); // truncate additional words
        cnt.innerHTML = maxwords;
        rem.innerHTML = 0;
        return false;
    }
    return true;
} 

</script>

HTML

   <textarea name="Message 1" onkeypress="
 return check_length(this,
 document.getElementById('count1'),
 document.getElementById('remaining1'));"></textarea>
Word count: <span id="count1">0</span> &nbsp;
Words remaining: <span id="remaining1">250</span>

<textarea name="Message 2" onkeypress="
 return check_length(this,
 document.getElementById('count2'),
 document.getElementById('remaining2'));"></textarea>
Word count: <span id="count2">0</span> &nbsp;
Words remaining: <span id="remaining2">500</span>

Does anyone know a solution to this problem?

Thanks in advance,
Tom

  • 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-06T11:51:59+00:00Added an answer on June 6, 2026 at 11:51 am

    Add an extra parameter to your function, and send it the maxWords from each function call:

    function check_length(obj, cnt, rem, maxwords)
    {
    //... rest of the function would stay the same
    

    and when you call it, include the max words

    <textarea name="Message 2" onkeypress="
     return check_length(this,
     document.getElementById('count2'),
     document.getElementById('remaining2'), 250);"></textarea>
    Word count: <span id="count2">0</span> &nbsp;
    Words remaining: <span id="remaining2">500</span>
    

    To remove the words remaining,

    function check_length(obj, cnt, maxwords)
    {
        var ary = obj.value.split(" "); // doubled spaces will throw this off
        var len = ary.length;
        cnt.innerHTML = len;
    
        if (len > maxwords) {
            alert("Message in '" + obj.name + "' limited to " + maxwords + " words.");
            ary = ary.slice(0,maxwords-1);
            obj.value = ary.join(" "); // truncate additional words
            cnt.innerHTML = maxwords;
            return false;
        }
        return true;
    } 
    

    and in your HTML,

    <textarea name="Message 1" onkeypress="
    return check_length(this,
    document.getElementById('count1'),250);"></textarea>
    Word count: <span id="count1">0</span> &nbsp;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a website that has 5 different sub-sites each with the same
I am creating a website. It has a database and I'm trying to work
I am creating a website in hibernate + spring. There is a job form
I am creating a website which has 1 dropdownlist that bound to Northwind database,
So I'm creating a website that has all of its content in one centered
I am creating a website where you post, and the form content is saved
I am working on creating website with Yii framework and I have a problem
When creating a website using Asp.Net and using controls such as the ListView is
I'm creating a website and as I am thoroughly enjoying using SASS/Compass for organizing
I am creating a website for teaching some arabic words. I am including numbers,

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.