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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:28:50+00:00 2026-05-24T22:28:50+00:00

Let us consider i am having a text box where i can enter user

  • 0

Let us consider i am having a text box where i can enter user names separated by commas.

EDIT: In Detail:

  1. I am having a text box and a search_button nearby.

  2. When i click on the search box list of users will be displayed there in a popup with a check box nearby

  3. When the user the clicks the check box and clicks submit the corresponding users name will be displayed on the text box.

  4. My problem is: I should not able to add the user name twice. That is when i click on the same user which i added already, it should throw an alert message and that corresponding name should not be added in the text box.

My code for this is given below:

  var res_user = '';
  // checked username will get
  var existing_names = $('#text_box').val();
  $('#popups input[type="checkbox"]:checked').each(function() {
    res_user = res_user + $(this).parent().next().attr('value') + ', ';
  });
  if ($("#text_box").length > 0) {
    target = $("#text_box").val($("#text_box").val() + ' ' + res_user);
  }      
  Drupal.popups.close();
  return false;

How can this be done using Jquery.

Any help will be thankful and grateful….

Thanks in advance…

  • 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-24T22:28:51+00:00Added an answer on May 24, 2026 at 10:28 pm

    You can use this code. It puts all the newly selected users into an array. Then, it loops through that array, makes a regular expression out of each name and looks for that regex in the comma separated list. If it’s found, then we don’t add this one. If it’s not found, we add it.

    var selectedUsers = [];
    // checked username will get added to selectedUsers array
    $('#popups input[type="checkbox"]:checked').each(function() {
        selectedUsers.push($(this).parent().next().attr('value'));
    });
    
    var currentUsers = $("#text_box").val();
    var regex;
    for (var i = 0; i < selectedUsers.length; i++) {
        // make regex for this selectedUser so we can search to see if it's already there
        regex = new RegExp("(^|, )" + selectedUsers[i] + "(,|$)", "i"); 
        // if this username not found in the current string, then we can add it
        if (currentUsers.search(regex) == -1) {
             if (currentUsers.length != 0) {
                 currentUsers += ", ";
             }
             currentUsers += selectedUsers[i];
        }
    }
    // put updated user list back in the textbox
    $("#text_box").val(currentUsers);
    

    You can see a slightly modified version with my own HTML work here: http://jsfiddle.net/jfriend00/du6UF/.

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

Sidebar

Related Questions

Let's consider the following scenario: a function which can generate code colors from white
Let's consider the following scenario: I've a master table with a detail table. The
Let’s consider table Video( IDvideo(PK), Date, Description, User ) with mysql I have no
Let's consider this dictionary >>> test = {'to have': True, 'to get': False, 'having':
Let's consider python (3.x) scripts: main.py: from test.team import team from test.user import user
Let's consider the two following lines in C# (using framework .NET 3.5) Regex regex
Let's consider the following enum in C# public enum ScrollMode : byte { None
let's consider a small method: int MyFunction(string foo, int bar) { ... } and
Let's consider we have QWidget that contains QTableWidget (only). So we want to resize
Let's consider the below example. There, I have: target MAIN calls target t and

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.