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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:37:14+00:00 2026-06-18T08:37:14+00:00

I’m trying to figure out how to sync two multiple choice lists in javascript.

  • 0

I’m trying to figure out how to sync two multiple choice lists in javascript. Here’s the code which works:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>

<script language="JavaScript">
<!--

function SelectEmail(name)
{
    var listboxEmails = document.getElementById('emails');
    for (var i=0;i<listboxEmails.length;i++)
    {
        listboxname = listboxEmails[i].innerHTML
        if (listboxname == name)
        {
            listboxEmails.selectedIndex = i;
            break;
        }
    }//end for 
}//end function SelectEmail

// -->
</script>
<body>
<select id='names' name ='names' style = "width: 100" multiple="multiple" onClick="SelectEmail(this.value);">
    <option value ="joe">joe</option>
    <option value ="albert">albert</option>
    <option value ="gary">gary</option>
    <option value ="ace">ace</option>
</select>

<select id="emails" name ="emails" style = "width: 100;"  multiple="multiple">
    <option value ="joe@asds.com">joe</option>
    <option value ="albert@asds.com">albert</option>
    <option value ="gary@asds.com">gary</option>
    <option value ="ace@asds.com">ace</option>
</SELECT>
</body>
</html>

However I want to make it show multiple choices. So for example if I choose albert and gary on the left list, I want the right list to select albert and gary as well. Please help me with this. Cheers.

  • 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-18T08:37:15+00:00Added an answer on June 18, 2026 at 8:37 am

    Your function SelectEmail() can’t work because it sets selectedIndex of your select, which selects one option and deselects the rest. Also, you are using the text content of the options in #emails in order to map them with the values of #names. That’s not a good practice, because text nodes are supposed to show text and not to enable the identification of elements in your script.
    Instead, you can access the selected attribute separately for each option you want to select. By adding an additional attribute to your #emails element’s options, it could look like:

    <select id="emails" name="emails" style="width: 100;" multiple="multiple">
        <option value="joe@asds.com" data-name="joe">joe</option>
        <option value="albert@asds.com" data-name="albert">albert</option>
        <option value="gary@asds.com" data-name="gary">gary</option>
        <option value="ace@asds.com" data-name="ace">ace</option>
    </select>
    

    You can now use the data-name attribute to map the options, for example in the following way:

    function selectEmail() {
        // deselect all
        $('#emails option').removeAttr('selected');
        var names = $('#names').val();
        if (names == null) {
            // none selected
            return;
        }
        $.each(names, function (i, name) {
            var selector = 'option[data-name="' + name + '"]';
            $('#emails ' + selector).attr('selected', true);
        });
    }
    

    Here’s a working fiddle (you will notice that I also used the onchange event instead of onclick:
    http://jsfiddle.net/H9hNH/2/

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm trying to select an H1 element which is the second-child in its group
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Basically, what I'm trying to create is a page of div tags, each has

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.