E' molto grezzo come codice
ma essendo di facile lettura
può penso esserti utile a costruire
quello che vuoi fare:
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
var check = false;
function createSelect( myarray )
{
var myselect = document.createElement("select");
myselect.setAttribute("id", "myselect");
document.getElementById("frm").appendChild(myselect);
var myoption = new Array();
for (i=0; i < myarray.length; i++)
{
myoption[i] = document.createElement("option");
myoption[i].setAttribute("value", i);
var text = document.createTextNode(myarray[i]);
myoption[i].appendChild(text);
document.getElementById("myselect").appendChild(myoption[i]);
}
start();
}
function createSelect2(myarray)
{
if(test = document.getElementById("myselect2"))
{
document.getElementById("frm").removeChild(test);
}
var sel = document.getElementById("myselect");
var index = sel.options[sel.selectedIndex].value;
var myselect2 = document.createElement("select");
myselect2.setAttribute("id", "myselect2");
document.getElementById("frm").appendChild(myselect2);
for (i=0; i < myarray[index].length; i++)
{
document.getElementById("myselect2").options[i] = new Option(myarray[index][i],i);
}
}
function start()
{
var myselect2 = document.createElement("select");
myselect2.setAttribute("id", "myselect2");
document.getElementById("frm").appendChild(myselect2);
document.getElementById("myselect2").options[0] = new Option("------","0");
}
window.onload = function()
{
var myarray = new Array("uno","due","tre");
var myarray2 = new Array();
myarray2[0] = new Array("uno","due","tre");
myarray2[1] = new Array("uno1","due1","tre1");
myarray2[2] = new Array("uno2","due2","tre2");
createSelect(myarray);
var sel = document.getElementById("myselect");
sel.onchange = function()
{
createSelect2(myarray2);
}
}
</script>
</head>
<body>
<form id="frm" action="" method="post" name="frm">
</form>
</body>
</html>