|
|
|
|
To move items [options] from one dropdown box[select box] to another is pretty simple.
Below is exactly how:
//This is the function called to
//move items from one select box to another
function moveIt(moveFrom,moveTo)
{
var oMoveFrom =
document.getElementById(moveFrom);
var oMoveTo =
document.getElementById(moveTo);
addIt(oMoveFrom,oMoveTo);
removeIt(oMoveFrom);
}
//This is the function that
//adds it from the "oMoveFrom" to the "oMoveTo"
function addIt(oMoveFrom,oMoveTo)
{
//loop though all elements
for (var i=0; i < oMoveFrom.length;i++)
{
if (oMoveFrom[i].selected)
{
//Create new OPTION element and set the new values
oNewOption = document.createElement("OPTION");
oNewOption.value = oMoveFrom[i].value;
oNewOption.text = oMoveFrom[i].text;
//Add oNewOption to oMoveTo
oMoveTo.add(oNewOption,oMoveTo.length);
}
}
}
//This is the recursive function that
//removes it from the "oMoveFrom"
function removeIt(oMoveFrom)
{
//loop though all elements
for (var i=0; i < oMoveFrom.length;i++)
{
if (oMoveFrom[i].selected)
{
//Remove it from oMoveFrom
oMoveFrom.remove(i);
removeIt(oMoveFrom); //recursive funtion;
break;
}
}
}
Add the following event to your an input button and tada, they move across.
onclick="moveIt('sltBox1','sltBox2');"
|
|
|
|
|
|