PDA

View Full Version : Help needed - Moving values to another drop down



harikrishna_di
05-19-2009, 06:05 AM
Hi,

I want to move values from one drop down to another drop down. When I move the selected value is being removed from first drop down. Instead, I want to keep the value in first drop down & move it to second drop down.

This is the code i am using.


function moveoutid()
{
var sda = document.getElementById('fromList');;
var len = sda.length;
var sda1 = document.getElementById('toList');
for(var j=0; j<len; j++)
{
if(sda[j].selected)
{
var tmp = sda.options[j].text;
var tmp1 = sda.options[j].value;
sda.remove(j);
j--;
var y=document.createElement('option');
y.text=tmp;
try
{sda1.add(y,null);
}
catch(ex)
{
sda1.add(y);
}
}
}
}

function moveinid()
{
var sda = document.getElementById('fromList');
var sda1 = document.getElementById('toList');
var len = sda1.length;
for(var j=0; j<len; j++)
{
if(sda1[j].selected)
{
var tmp = sda1.options[j].text;
var tmp1 = sda1.options[j].value;
sda1.remove(j);
j--;
var y=document.createElement('option');
y.text=tmp;
try
{
sda.add(y,null);}
catch(ex){
sda.add(y);
}

}
}
}

vwphillips
05-19-2009, 01:33 PM
<html>

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/

function Move(from,to){
from=document.getElementById(from);
document.getElementById(to).appendChild(from.options[from.selectedIndex].cloneNode(true));
}
/*]]>*/
</script></head>

<body>
<select id="S1" >
<option >S1 1</option>
<option >S1 2</option>
<option >S1 3</option>
</select>
<select id="S2" >
<option >S2 1</option>
<option >S2 2</option>
<option >S2 3</option>
</select>
<input type="button" name="" value="S1 > S2" onclick="Move('S1','S2');" />
<input type="button" name="" value="S2 > S1" onclick="Move('S2','S1');" />

</body>

</html>