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

  • Home
  • SEARCH
  • 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 7863061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:21:33+00:00 2026-06-02T23:21:33+00:00

I am trying to add multiple values to a hidden field. It’s working fine,

  • 0

I am trying to add multiple values to a hidden field.
It’s working fine, but I want the values which are getting added in the hidden field to be unique and not to get added if a value is entered more than once.

interestedin is the name of the selectbox where the values are selected and interest is the id of the hiddenfield where the values are getting added as comma separated values while selecting options in the selectbox.

if a same option is selected twice, it’s getting added in the hidden field twice. I don’t want any values to get added in the hidden fields though its selected twice.

the function clicker is called while selecting the values in the select box(name=”interestedin”) and the values will be added in the hidden field (id=”interest”)

function clicker(){
            var itemsobj=document.getElementsByName("interestedin[]");
            str='';
            //alert(itemsobj[0].value);
            //alert('test');
            count=0;
            var arr = new Array();
    for(var i=0;i<itemsobj.length;i++)
        {
            count += 1;
            str +=itemsobj[i].value+',';
            //alert(str);
            arr[i] = itemsobj[i].value; 
                }
            var length=str.length;
            var strr=str.substring(0,length-1);
            document.getElementById('interest').value = strr;
            //alert(strr);


            setProductPrice(arr,count);
        }
  • 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-02T23:21:34+00:00Added an answer on June 2, 2026 at 11:21 pm

    Hiya sup man hope this helps as I just resolved for some demo http://jsfiddle.net/Yvnfx/
    or without alert http://jsfiddle.net/Yvnfx/1/

    For case – if you deleted the selected autocomplete http://jsfiddle.net/wbQZU/4/

    Autocomplete (like facebook) has give up a duplicate value

    Idea is to created NewArray = AvailableTagsArray - UsedItemArray

    This will help and hope demo makes it more clear,! B-)

    Jquery code to avoid duplicate array

    **var usedItems = []**
    :
    :// then
    source: function(request, response) {
    
          //build new array with = AvailableTagsArray - UsedItemArray
                 var newNonDuplicatetag = $.grep(availableTags, function(el){return $.inArray(el, usedItems) == -1});
    
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                newNonDuplicatetag, extractLast(request.term)));
            },
    

    Full Jquery from my demo

    $(function() {
        var usedItems = [];
    
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
            ];
    
        function split(val) {
            return val.split(/,\s*/);
        }
    
        function extractLast(term) {
            return split(term).pop();
        }
    
    
        $("#tags")
        // don't navigate away from the field on tab when selecting an item
        .bind("keydown", function(event) {
            if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
                event.preventDefault();
            }
        }).autocomplete({
            minLength: 0,
            source: function(request, response) {
                 var newNonDuplicatetag = $.grep(availableTags, function(el){return $.inArray(el, usedItems) == -1}); 
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                newNonDuplicatetag, extractLast(request.term)));
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                usedItems.push(ui.item.value);
                alert(usedItems[1]);
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
    });
    
    
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to upload multiple images using meioupload which works fine if I
Hi guys I am trying to post values which is getting number from another
I'm trying to add multiple instances of UIImageView(s) to an NSMutableArray of NSMutableDictionar(ies). I
I'm trying to add multiple jQuery data entries to a single element. I suspected
I'm fairly new to JQuery and I'm trying to add multiple form fields for
Ok, I am trying to add one row of multiple images to a JPanel,
Trying to add a new element to the DOM but I get all sorts
I am trying to perform a calculation on multiple values in the value portion
I'm trying to use ConfigurationManager.AppSettings.GetValues() to retrieve multiple configuration values for a single key,
I have a hash table generated which I am then trying to add to

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.