Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move from list to another list 1

Status
Not open for further replies.

discusmania

IS-IT--Management
Oct 24, 2000
158
AP
hi guys....
let say i have 2 listbox. and a button. What i want is : when i pick an item from list1 and click the button, the item will be move from list1 to list2. how to do that?

Thanks so much

 
<HTML>
<BODY>
<SELECT size=6 id=&quot;list1&quot; name=&quot;list1&quot;>
<OPTION value=&quot;1&quot;>1
<OPTION value=&quot;2&quot;>2
<OPTION value=&quot;3&quot;>3
<OPTION value=&quot;4&quot;>4
<OPTION value=&quot;5&quot;>5
</SELECT>
<br>
<input type=&quot;button&quot; value=&quot;Add&quot; onclick=&quot;doAdd()&quot;>
<br>
<SELECT size=6 id=&quot;list2&quot; name=&quot;list2&quot;>
</select>
</BODY>
<script language=&quot;javascript&quot;>
function doAdd()
{
var list1value=list1.value;
list1.remove(list1.selectedIndex);
var listelem=document.createElement(&quot;OPTION&quot;);
listelem.text=list1value;
listelem.value=list1value;
list2.add(listelem);

};
</script>
</HTML>
________

George
 
Thanks alot... that actually what i'm looking for. Just one more doubt, how to do multiple move?... means that ,select more than 1 field from list 1 and move it to list2 at one click?


Thanks
Ron
 
hope this works...

<HTML>
<BODY>
<SELECT size=6 id=&quot;list1&quot; name=&quot;list1&quot; multiple>
<OPTION value=&quot;1&quot;>1
<OPTION value=&quot;2&quot;>2
<OPTION value=&quot;3&quot;>3
<OPTION value=&quot;4&quot;>4
<OPTION value=&quot;5&quot;>5</OPTION>
</SELECT>
<br>
<input type=&quot;button&quot; value=&quot;Add&quot; onclick=&quot;doAdd()&quot;>
<br>
<SELECT size=6 id=&quot;list2&quot; name=&quot;list2&quot;>
</SELECT>
</BODY>
<script language=&quot;javascript&quot;>

function doAdd()
{
for(i=0;list1.length;i++)
{
if(list1.options(i).selected)//see what element is selected
{
var list1value=list1.options(i).value;
list1.remove(i);
var listelem=document.createElement(&quot;OPTION&quot;);
listelem.text=list1value;
listelem.value=list1value;
list2.add(listelem);
i=-1;//try again from begining of list to see if selected
};
};

};
</script>
</HTML>
________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top