PDA

View Full Version : Listbox - copy/remove options


Haddok
09-18-2002, 02:05 PM
:confused: I want to copy text from one listbox to another, [a] -> [b] by clicking a button.

Now, my problem is that I want to be able to remove copied options from [b] and at the same time remove the row (ie no blank rows as options).

The copy looks like this:
function copyOption()
{
document.f1.lstAddedMethod.options[document.f1.lstAddedMethod.length++].text = document.f1.lstMethodAlternative.options[document.f1.lstMethodAlternative.selectedIndex].text;
}
(This moves the selected option from [a] to [b],

The remove looks like this = My problem
function removeOption()
{
My idea : document.f1.lstMethodAlternative.options[document.f1.lstMethodAlternative.selectedIndex].text = "";
This does however not remove the row from [b]
}

Alekz
09-18-2002, 03:15 PM
Hi,
Try this:

function moveOptions(ListFrom,ListTo){
var i,myOption;
/* For example:
ListFrom = document.frm.list_from;
ListTo = document.frm.list_to;
*/

for(i=0;i<ListFrom.options.length;i++){
if (ListFrom.options[i].selected){
myOption = new Option(ListFrom.options[i].text,ListFrom.options[i].value);
ListTo.options[ListTo.options.length] = myOption;
}
}
i = 0;
while(i<(ListFrom.options.length)){
if (ListFrom.options[i].selected)
ListFrom.options[i] = null;
else
i++;
}
}


Alex

Haddok
09-18-2002, 03:42 PM
:thumbsup:

Thanx!