File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes moving items from one html:select to another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "moving items from one html:select to another" Watch "moving items from one html:select to another" New topic

moving items from one html:select to another

Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
We are moving selected list of items from one <html:select> to another when the user clicks on button. For eg:

We have list of items in one list box


When the user selects Test1 and clicks on a button with label >, then Test1 should be shown in the second list box.For eg:

ListBox1 ListBox2
Testt2 Test1

Please let us know how to go about.

SCJP 1.4, SCWCD 1.4
your eyes cannot see what your mind does not know
Arulanand Dayalan
Ranch Hand

Joined: Aug 10, 2005
Posts: 124
On click of that > button write a javascript to move the element to the other select box. You google for Picklist source code.
Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
hii Arulanand

thanks a lot. we are able to find the code for pick list and were able to implement what we wanted. actually we did not know its called pick list..

thanks a tonn
Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30

this is the code for the same

function moveToSelectedProjects()
domSwap(document.getElementById('projectList'), document.getElementById('selectedProjectList'));

function moveFromSelectedProjects()
domSwap(document.getElementById('selectedProjectList'), document.getElementById('projectList'));

// call the above two functions from your html page to move the item in the list

function domSwap(fromList, toList) {
// If nothing is selected then return
var selIndex = fromList.selectedIndex;
if(selIndex < 0) { return; }

// Prepare variables
var arrLookup = new Array(); // To quickly find the index of the text
var arrToList = new Array(); // To use JavaScripts builtin sort
var newToList = toList.cloneNode(false); // Only clone the parent

// Decrement to keep the changing index from affecting the moves
for(var i = fromList.length - 1; i >= 0; i--) {
arrLookup[fromList.options.item(i).text] = i;
if(fromList.options.item(i).selected) {
// Append to the toList unsorted initially


Rajul Konkar

Joined: Nov 05, 2008
Posts: 20

Hi All,

I am too facing same problem , using javascript i am able to transfer the list items across both list
but the result is not reflecting in the respective actions (or formbean variables) , can anybody tell me the reason for it

Please refer the code below :

Rajul Konkar
Only pioneer take the untravelled path

Only pioneer take the untraveled path

I agree. Here's the link:
subject: moving items from one html:select to another
It's not a secret anymore!