aspose file tools*
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 8 in Action this week in the Java 8 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
Author

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

Test1
Testt2
Test3

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
Test3

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
regards
anuj
Anuj Troy
Ranch Hand

Joined: Apr 07, 2005
Posts: 30
hii

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
toList.appendChild(fromList.options.item(i));
}
}

}

Rajul Konkar
Greenhorn

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: http://aspose.com/file-tools
 
subject: moving items from one html:select to another
 
Similar Threads
Problem while uploading xls file through Servlet program.
Access all items in Select Box.
adding a SelectItem object at particular index position in java.util.list
disabled field with selected value
ActionForm question (struts 1)