<html>
<head>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
function one2two()
{

<?php

$result = mysql_query("select * from ufficio") or db_die();
$numero_righe=mysql_num_rows($result);

echo "var nRighe = $numero_righe;\n";
echo "var nColonne = 3;\n";
echo "var numero_uffici;\n";
echo "var lista_uffici = new Array(nRighe);\n";
$k=0;
while ($row = mysql_fetch_row($result))
{
echo "lista_uffici[$k] = new Array(nColonne);\n";
echo "lista_uffici[$k]=[\"$row[0]\",\"$row[1]\",\"$row[2]\"];\n";
$k++;
}
echo "numero_uffici=$k;";
?>



arrSelected = new Array();
var count = 0;
var variable;

var num = document.theForm.elements["menu1[]"].length;

boxLength=menu1.length;
alert(num);
ufficiLength=menu2.length;

alert(ufficiLength);

for (j = ufficiLength-1; j>=0; j--)
{
document.theForm.menu2.options[j] = null;
}

for (i = 0; i < boxLength; i++)
{
if (document.theForm.menu1.options[i].selected)
{
arrSelected[count] = document.theForm.menu1.options[i].value;
count++;
}

}

var totale=0;
for ( i=0; i<count ; i++)
{
for (k = 0; k < numero_uffici; k++)
{
if(lista_uffici[k][2]==arrSelected[i])
{
newoption = new Option(lista_uffici[k][1], lista_uffici[k][0], false, false);
document.theForm.menu2.options[totale] = newoption;
totale++;
}
}
}
}
//-->
</script>
<h2>JavaScript : Select Menu List</h2>





Here is an example:

<?php
echo "il valore scelto menu2 e' $menu2
";
echo "il valore scelto menu1 e' $menu1
";

?>
<form method="POST" name="theForm" action="prova_script.php">
<table bgcolor=white border=1 cellpadding=5 cellspacing=2 align=center >
<tr><td align=center>
<select name="menu1[]" size=10 multiple>

<?php
$result = mysql_query("select * from gruppen") or db_die();
while ($row = mysql_fetch_row($result))
{
echo "<option value=$row[0]>$row[1]</option>\n";
}
?>
</select>

<p align=center><input type="button" onClick="one2two()" value=" >> "></p>

</td><td align=center>

<select name="menu2[]" size=10 multiple >

</select>



</td></tr>
<tr><td><input type=Submit value="Invia"></td><tr>
</table>
</form>



</p>




<script language="JavaScript">
// shorthand for refering to menus
// must run after document has been created
// you can also change the name of the select menus and
// you would only need to change them in one spot, here
var array
var m1 = document.theForm.menu1;
var m2 = document.theForm.menu2;
</script>




</p>
</td></tr></table>

</body>
</html>