garethhall Posted November 14, 2009 Share Posted November 14, 2009 Hello, I have this function that runs when you click a button. This functions take the selected items from box A adds it to box B and removes it from box A. Now this works ok but, as soon as you do a second selection then the remove from box A don't work. Any help would be great function addExt(){ var toRemExt = new Array(); //Create array to hold items to remove elm = document.getElementById('ext'); for(e = 0; e < elm.length; e++){ //loop all the select box items if(elm.options[e].selected){ //work with only the selected items addOption(document.frmExt.curExt, elm.options[e].value, elm.options[e].value); //Add option approved side toRemExt[e] = elm.options[e].value; //write item value to the array } /*** If at the end off the loop remove the items matching the array ***/ if(e == (tExt-1)){ for(a = 0; a < toRemExt.length; a++){ //loop throught the array for(f = 0; f < elm.length; f++){ //for each item in the array loop through the items in the select box if(toRemExt[a] == elm.options[f].value){ //if items match then removeOption(document.frmExt.ext,f); //remove item from select box } } } } //endif } } Link to comment https://forums.phpfreaks.com/topic/181461-adding-and-removing-items-from-a-select-box-works-ones-then-fails/ Share on other sites More sharing options...
JustLikeIcarus Posted November 16, 2009 Share Posted November 16, 2009 Why not just do function addExt(){ var toRemExt = new Array(); //Create array to hold items to remove elm = document.getElementById('ext'); for(e = 0; e < elm.length; e++){ //loop all the select box items if(elm.options[e].selected){ //work with only the selected items addOption(document.frmExt.curExt, elm.options[e].value, elm.options[e].value); //Add option approved side removeOption(document.frmExt.ext,e); //remove item from select box } } } [code] Link to comment https://forums.phpfreaks.com/topic/181461-adding-and-removing-items-from-a-select-box-works-ones-then-fails/#findComment-958504 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.