anropas:
<input type="button" onClick="move_selected(document.form.första, document.form.andra);" value="flytta till andra">
<select name="första">
...
</select>
<select name="andra">
...
</select>
<script language="javascript">
var unknown_emails = "";
function move_selected(select1, select2) {
var selected = select1.selectedIndex;
if (select1.selectedIndex == -1)
{
alert("Du måste välj någon först");
return;
}
//loopa å kolla om den redan finns...
var ex = false;
for (var i = 0; i < select2.options.length; i++)
{
if (select2.options[i].value == select1.options[select1.selectedIndex].value)
ex = true;
}
if (!ex) //om den inte fanns - flytta
{
//göra ny i den andra select-boxen
add_item(select2, select1.options[select1.selectedIndex].text, select1.options[select1.selectedIndex].value);
//ta bort från första
remove_item(select1, select1.selectedIndex);
}
//markera select1
if (selected == select1.options.length) //man valde den sista
select1.selectedIndex = select1.options.length-1;
else
select1.selectedIndex = selected;
}
function remove_item(select, index)
{
select.options[index] = null;
}
function add_item(select, textaaa, valueaaa)
{
new_option = new Option(textaaa, valueaaa);
select.options[select.options.length] = new_option;
return;
}
</script>
------------------
/bohlin

