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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:18:31+00:00 2026-06-01T16:18:31+00:00

Hi guys I have this script here, which counts the characters and lines, now

  • 0

Hi guys I have this script here, which counts the characters and lines, now currently though it still allows lines and characters to go into minus, but I would like it to also put up a warning box so it stops the user from being able to put in more text, could you help me out?

javascript:

function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine) {
    var strTemp = "";
    var strLineCounter = 0;
    var strCharCounter = 0;

    for (var i = 0; i < theField.value.length; i++)
    {
        var strChar = theField.value.substring(i, i + 1);
        if (strChar == '\n')
        {
            strTemp += strChar;
            strCharCounter = 1;
            strLineCounter += 1;
        }
        else if (strCharCounter == maxPerLine)
        {
            strTemp += '\n' + strChar;
            strCharCounter = 1;
            strLineCounter += 1;
        }
        else
        {
            strTemp += strChar;
            strCharCounter ++;
        }
    }

    theCharCounter.value = maxChars - strTemp.length;
    theLineCounter.value = maxLines - strLineCounter;
}

and used in code:

<textarea name="comment" cols="50" rows="10" wrap="VIRTUAL" onKeyUp="textCounter(theForm.comment,theForm.remChars,remLines,900,30,50);"></textarea>
<br><input name=remChars type=text value="900" size=3 maxlength=3 readonly> characters left
<br><input name=remLines type=text value="30" size=3 maxlength=3 readonly> lines left<br>

Report to moder

  • 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-01T16:18:33+00:00Added an answer on June 1, 2026 at 4:18 pm

    1 – Add a check to the end of the function:

    var check = strTemp.length <= maxChars && strLineCounter <= maxLines;
    if (!check) alert("Error message here!");
    

    2 – Trim the text of the field, so it contains only the needed chars:

    theField.value = theField.value.sbustring(0, maxChars - 1);
    

    3 – Add a return to the end of the function:

    return check ;
    

    4 – And change the event binding to:

    onKeyUp="return textCounter(theForm.comment,theForm...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys i have arrays in which i have to match this kind of text
Hey guys, I have this sign up script and I'm using mysql_real_escape_string .I know
hey guys i have got this far with a chat system but now i
Hey guys I have my script here that is supposed to do some stuff
Thus far you guys have been wildly helpful with me getting this little ditty
Can you guys help me figure this out? I have the following JavaScript snippet:
Ok guys, I have a serious problem with this. I have a static class
Hey guys, this is simple but I can't make it workn... blah! I have
I hope some of you guys can help me with this problem.... I have
So I have this SQL table that I need to update. Now we use

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.