TGML screwed up the first post. use this instead:
/*
pushall takes the following arguments:
from - a reference to a selectbox to move the items out of
to - a reference to a selectbox to move the items into
send - whether to actually send to the other box, or just remove from here
discard - should i remove them from the from argument
validate - an optional parameter to call a function that must return true or false
the item in question will be passed as an argument to this function
Note: you must also include pushSel to use this
*/
function pushAll(from,to,send,discard,validate)
{
fromar=from.options;fromlen=fromar.length;
for(var i=0;i<fromlen;i++)
{
fromar
.selected=true;
}
pushSel(from,to,send,discard,validate||false)
}
/*
pushall takes the following arguments:
from - a reference to a selectbox to move the items out of
to - a reference to a selectbox to move the items into
send - whether to actually send to the other box, or just remove from here
discard - should i remove them from the from argument
validate - an optional parameter to call a function that must return true or false
the item in question will be passed as an argument to this function
Note: send or discard must be true or there is no point
*/
function pushSel(from,to,send,discard,validate)
{
var fromar,fromlen
validate=validate||function (){return true}
fromar=from.options;fromlen=fromar.length;
if(!send && !discard){top.status='pushSel: args 2&3 both false - no point';return true} //stay for val?not likely.
for(var i=0;i<fromlen;i++)
{
if(fromar==null){continue}
if(fromar.selected)
{
if(validate(fromar))
{
//do them jive
if(send)
{
to.add(new Option(fromar(i).text,fromar(i).value))
if(discard){from.remove(i--);}
}
else if(discard){from.remove(i--);}
}
else{continue}
}
else{continue}
}
//these lines below kill a very odd bug, try commenting them out,
//scrolling the list to the bottom, and choosing the top item!
from.style.visibility='hidden'
from.style.visibility='visible'
}
</script>
heres an example:
<select hidefocus ondblclick="pushSel(this,boxbottom,true,true)" style="width:200px" size=10 multiple id="boxtop">
<option value="tiger">Tiger Man
<option value="flute">Flute Man
<option value="dog">Dog Man
<option value="shark">Shark Man
<option value="flute">Flute Man
<option value="dog">Dog Man
<option value="shark">Shark Man
<option value="flute">Flute Man
<option value="dog">Dog Man
<option value="shark">Shark Man
<option value="flute">Flute Man
<option value="dog">Dog Man
<option value="shark">Shark Man
<option value="flute">Flute Man
<option value="dog">Dog Man
<option value="shark">Shark Man
<option value="flute">Flute Man
<option value="dog">Dog Man
<option value="shark">Shark Man
</select>
<br><br>
<button onClick="pushAll(boxtop,boxbottom,true,true)">All top to bottom</button>
<button onClick="pushSel(boxtop,boxbottom,true,true)">Selected top to bottom</button>
<button onClick="pushAll(boxbottom,boxtop,true,true)">All bottom to top</button>
<button onClick="pushSel(boxbottom,boxtop,true,true)">Selected bottom to top</button>
<br><br>
<select style="width:200px" size=10 multiple id="boxbottom">
</select>
jared@eae.net -