1

Hi I am trying to pass selected item from one multiple combo box to another to multi combobox.

How do I do that? is there any example for that?

<HTML>
<HEAD>
  <TITLE></TITLE>
</HEAD>
<BODY>
  <SELECT NAME="possible" SIZE"10" MULTIPLE>
    <OPTION VALUE="New Red Corvette">New Red Corvette</OPTION>
    <OPTION VALUE="Vintage Red Corvette">Vintage Red Corvette</OPTION>
    <OPTION VALUE="Old Red Corvette">Old Red Corvette</OPTION>
  </SELECT>
  <SELECT NAME="wishlist" SIZE="10" MULTIPLE>
    <OPTION VALUE="Old Red Jalopy">Old Red Jalopy</OPTION>
  </SELECT>


<INPUT TYPE="BUTTON" VALUE="Add to wishlist"
       ONCLICK="MyMoveItem(possible,wishlist);">
<INPUT TYPE="BUTTON" VALUE="Remove from wishlist" 
       ONCLICK="MyMoveItem(wishlist,possible);">

</BODY>
</HTML>
2
  • Can you share with us, what have you tried so far ? Commented Mar 16, 2016 at 14:15
  • 1
    What does your MyMoveItem() function look like? Commented Mar 16, 2016 at 14:17

1 Answer 1

1

$("#b1").click(function(){
  $("#s2").append( $("#s1 option:selected"))
})

$("#b2").click(function(){
  $("#s1").append( $("#s2 option:selected"))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<SELECT id="s1" NAME="possible" SIZE"10" MULTIPLE>
    <OPTION VALUE="New Red Corvette">New Red Corvette</OPTION>
    <OPTION VALUE="Vintage Red Corvette">Vintage Red Corvette</OPTION>
    <OPTION VALUE="Old Red Corvette">Old Red Corvette</OPTION>
  </SELECT>
  <SELECT id="s2" NAME="wishlist" SIZE="10" MULTIPLE>
    <OPTION VALUE="Old Red Jalopy">Old Red Jalopy</OPTION>
  </SELECT>


<INPUT TYPE="BUTTON" id="b1" VALUE="Add to wishlist"
       ONCLICK="MyMoveItem(possible,wishlist);">
<INPUT TYPE="BUTTON" id="b2" VALUE="Remove from wishlist" 
       ONCLICK="MyMoveItem(wishlist,possible);">

Sign up to request clarification or add additional context in comments.

2 Comments

There is no need for the remove() as jQuery realizes the element already exists and it moves it instead of cloning it.
Just wanted to add that this solution also handles multiple selected items holding the CTRL key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.