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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:13:07+00:00 2026-06-01T12:13:07+00:00

So I have two multiple select boxes like this <select id=foo multiple=multiple> <option value=1>Option

  • 0

So I have two multiple select boxes like this

<select id="foo" multiple="multiple">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
</select>

<select id="bar" multiple="multiple">
    <option value="1">Opt 1</option>
    <option value="2">Opt 2</option>
    <option value="3">Opt 3</option>
    <option value="4">Opt 4</option>
</select>
<a href="#" onclick="select()">Select</a>

What I’m trying to do is that when ‘Select’ is clicked, any option in “#bar” that has the same value with an option in “#foo” would be selected. In this case Opt 1 and Opt 2 in “#bar” should be selected.
I’ve no idea why my javascript won’t work. I know it must be something very simple. I just can’t see it. 🙁
So my Javascript function is as followed:

function select(){
    var vals = new Array();
    var iter = 0;
    $("#foo option").each(function(){
        var v = $(this).val();
        $('#bar option').each(function(){
            if ($(this).val() == v)
            {
                vals[iter] = v;
                iter++;
                break;
            }
        });
    });
    $("#bar").val(vals);
 }
  • 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-01T12:13:08+00:00Added an answer on June 1, 2026 at 12:13 pm

    UPDATE after seeing KON’s example

    DEMO

    $("#sel").click(function(e) {
      e.preventDefault(); // cancel the link itself
      $("#bar").val($("#foo").val());
    });
    

    <a href="#" id="sel">Select</a>
    

    Older example using each

    DEMO

    $("#sel").click(function(e) { // when link clicked
      e.preventDefault();
      $("#foo option:selected ").each(function(){
        var v = $(this).attr("value"); // first select's value
        $('#bar option').each(function(){
          if ($(this).attr("value") == v) { 
            $(this).attr("selected",true); // select if same value
          }
        });
      });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two multiple select boxes. I need to use JQuery to drag selected
Let's say I have a multiple select box: <select id=sel multiple=multiple> <option value=1>One</option> <option
I have two g:select comboboxes that I want to add to the multiple select
I have two multiselect <select multiple=multiple name=cselect id=cselect class=required style=width: 240px;> And the other
I have a form with a table that has two input boxes, a select
I have multiple select boxes on the page all of which share the same
I have a registration form with common registration fields and two multiple selection Lists
I want to delete multiple records at once. I have two tables, one that
We have an idl file with multiple interfaces defined, two of which have someting
I have a form in which a user can select multiple options in a

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.