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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:00:59+00:00 2026-05-15T08:00:59+00:00

I have a textarea which users can enter some tags. I need to limit

  • 0

I have a textarea which users can enter some tags.
I need to limit this tags to 20 tags.

Tags could be enterer this way

maytag1,mytag2,mytag3

What i wrote is this function

function limitTags()
{

    var tags        =   $("input[type=text][name=tags]").val()
    var tag         =   $.trim(tags);
    var selected            = new Array();

    /**
     * replace the last ','
     */
    if(tag.substring(tag.length - 1) == ",")
    {
         *///tag = tag.replace(tag.length - 1, '');
    }


    var enteredTags = tag.split(",");

    if( enteredTags.length > 20 )
    {
        //$("input[type=text][name=tags]").val(enteredTags.join(",", enteredTags));

        alert("Only 20 Tags allowed");
    }


}

The alert works just fine but, after the alert box is gone. i can continiue entering tags till the alert box appears.

What i need is cut the text after the messagebox which was entered also the last “,”

I hope i could ask my question clear.

Thanks

  • 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-05-15T08:01:00+00:00Added an answer on May 15, 2026 at 8:01 am

    You can use the slice method to cut the array down to 20 entries before setting the value:

    $("input[type=text][name=tags]").val(enteredTags.slice(0,20).join(","));
    

    See: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array/Slice

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a textarea. Users enter a block of text which
I have a program which has some Textareas / Labels these can be anywhere
I have textarea in my site(link shortening site) i want to user enter some
For my small wiki application, I mostly need to have the textarea used to
I have a textarea in a form, when I enter special characters in it,
I have a simple HTML Form that allows the user to enter some text
I have a simple comment section where users can post comments to another users
Java 1.5, Linux I do have a screen which contains different textareas and textfields.
I have a textarea with many lines of input, and a JavaScript event fires
Let's say I have an html form. Each input/select/textarea will have a corresponding <label>

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.