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 textarea field where users can enter content. When it comes to
I have a textarea within an HTML page into which my users paste content.
I would like to have some functionality by which if I write <textarea maxlength=50></textarea>
I have a text area into which users enter a lot of text that
I have a situation where users can submit feedback through a textarea on a
I have a select element from which the users can select a value and
I have a system which allows users to enter HTML-reserved characters into a text
I have been struggling to create a django form which users can fill and
I have one text box in which the user can enter text as long
I have a textarea in which the user enters the following data: Paul:Nine, Rome

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.