Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Moving items from one select box to the other

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a requirement to display 2 select boxes (say "left" and "right") and be able to move items from one select box to the other and vice-versa with the click of 2 buttons (say "Move to Right" and "Move to Left")

This is simple, but the catch is that when I move the items back from "right" to "left" they should go back to the position in which they were earlier.

For example, when the page is first displayed I have the following items in the "left" select box (dynamically generated by querying the database)



Now, I move "General Manager" and "Sales Manager" from "left" to "right" and then move "General Manager" back from "right" to "left".
"General Manager" now appears at the botton in "left". My requirement is that it should appear at its original position i.e second in the list.

Is this even possible? And if yes, can someone please point me in the correct direction to get this done.

Thanks in advance !!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just need to keep the original list in order in an array or something and when an item is moved back, remove everything, and add back what should be in there in the same order.

Or you can insert an item at the correct Option index...

leftOptions[index] = optionToBeMovedBack;
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic