Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

moving items from one html:select to another

 
Anuj Troy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arulanand Dayalan
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Android Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic