Moving ListBox options from one ListBox to another

I currently have 2 listbox controls. The listbox on the right has numerous list options in it (displayed as usernames) and the left listbox is empty. I have some buttons with javascript functions associated with them which moves items from the listbox on the right, to the listbox on the left, using the following:

function addRecipient()
  var recipientList = document.getElementById("lstRecipients");
  var memberList = document.getElementById("lstMembers");
  var addIndex = memberList.selectedIndex;
  if(addIndex < 0)
  selectNone(recipientList, memberList);

I have a removeRecipient function which reverses this process, putting selected items from the left listbox back into the list on the right.
However, in some scenarios I might end up inserting a username in the left hand listbox, without using these buttons, and it might appear in both list boxes. This I dont mind, but what I need to know is, when I use the remove button which calls the removeRecipient function to put the user back on the right hand listbox, I want to first check if this username (and underlying value) already exists in the right hand listbox, and if it does, simply remove it from the left listbox, so I dont end up with duplicates in the Right listbox.
Is there a way I can check for the existance of the left hand side selected listbox item within the right hand side listbox, so I can take the appropriate action from there?

Thanks in advance...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Define a function like this.

function isMemberInList(member, list) {
  for (i = 0; i < list.options.length; i++) {
    if (member == list.options[i].value) {
      return true;
  return false;

Then call it in your removeRecipient function, assuming you have the index of the recipient you are removing:

if ( !(isMemberInList(recipientList.options[removeIndex].value, memberList)) ) {
  // add it back to the first list as you did before

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Note that you may use options[i].text if your options don't have any value attributes.
StarnzyAuthor Commented:
Thanks for your quick response!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.