Ecco uno script che avevo scritto tempo fa. Dovrebbe fare per te.
File : test2196.php
codice:
<?php
if (isset($_POST["invia"])) {
$index = 1;
$array = $_POST["s"];
if (is_array($array)) {
foreach ($array as $key => $value) {
print "elemento $key - valore $value
";
} // foreach ($array as $key => $value)
} // if (is_array($array))
} // if (isset($_POST["invia"]))
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function sposta(sel1,sel2) {
if (sel1.selectedIndex < 0) {
return;
} // if (sel1.selectedIndex < 0)
//-------- Ricavo la riga selezionata
var oCurOption = sel1.options.item(sel1.selectedIndex);
//-------- Creo una nuova opzione
var oOption = document.createElement("OPTION");
//-------- La aggiungo alla seconda select
sel2.options.add(oOption);
//-------- Assegno i valori della prima select alla seconda
oOption.value = oCurOption.value;
oOption.text = oCurOption.text ;
//-------- Elimino la riga spostata
elimina(sel1);
} // function sposta(sel1,sel2)
function elimina(unSelect) {
if (unSelect.selectedIndex < 0) {
return;
} // if (unSelect.selectedIndex < 0)
unSelect.options.remove(unSelect.selectedIndex)
} // function elimina(unSelect)
function preSub(aForm) {
indice = 0;
oSelect = document.getElementById('s2');
nbElem = oSelect.length;
for (i=0;i<nbElem;i++) {
curOption = oSelect.options.item(i);
var hiddenVar = document.createElement('INPUT');
hiddenVar.name = 's['+indice+']';
hiddenVar.type = 'hidden';
hiddenVar.value = curOption.value;
aForm.appendChild(hiddenVar);
indice++;
} // for (i=0;i<nbElem;i++)
return true;
} // function preSub()
//-->
</script>
</head>
<body>
<form name="myform" action="test2196.php" method="post" onsubmit="return preSub(this)">
<select id="s1" size="5" >
<option value="10000">10000</option>
<option value="20000">20000</option>
<option value="30000">30000</option>
<option value="40000">40000</option>
<option value="50000">50000</option>
<option value="60000">60000</option>
<option value="70000">70000</option>
<option value="80000">80000</option>
<option value="90000">90000</option>
</select>
<input type="button" value=">" onclick="sposta(document.getElementById('s1'),document.getElementById('s2'))">
<input type="button" value="<" onclick="sposta(document.getElementById('s2'),document.getElementById('s1'))">
<select id="s2" name="s2" size="5" multiple="true" >
</select>
<input type="button" value="-" onclick="elimina(document.getElementById('s2'))">
<input type="submit" value="Submit" name="invia">
</form>
</body>
</html>