codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function ltrim(item) {
return item.replace(/^\s*/gi,"");
}
function rtrim(item) {
return item.replace(/\s*$/gi,"");
}
function trim(item) {
return rtrim(ltrim(item));
}
function chgPadre(aValue) {
//--------- Svuoto la seconda select - IE only
firstValue = "";
var destSel = document.getElementById('sel2');
lenDest = destSel.options.length;
for (i=lenDest-1;i>=0;i--) {
destSel.remove(i);
} // for (i=lenDest-1;i>=0;i--)
//--------- Percorro l'array
lenArr = padri.length;
for (i=0;i<lenArr;i++) {
curLine = padri[i];
//-------- Cerco la prima virgola
posPVirg = curLine.indexOf(',');
//
if (curLine.substr(0,posPVirg) == aValue) {
curElement = curLine.substr(posPVirg+1,curLine.length);
//--------- Cerco la seconda virgola
posSVirg = curElement.indexOf(',');
oValue = curElement.substr(0,posSVirg);
oText = curElement.substr(posSVirg+1,curElement.length);
//--------- Creo l'opzione
var newOpt = document.createElement('OPTION');
ind = destSel.options.length;
destSel.options.add(newOpt,ind);
newOpt.value = oValue ;
newOpt.text = oText;
if (firstValue == "") {
firstValue = oValue;
} // if (firstValue == "")
} // if (lenArr[i].substr(0,posPVirg-1) == aValue)
} // for (i=0;i<lenArr;i++)
//--------- Caso non trovo niente
if (destSel.options.length == 0) {
var newOpt = document.createElement('OPTION');
ind = destSel.options.length;
destSel.options.add(newOpt,ind);
newOpt.value = '' ;
newOpt.text = '----------------------';
} // if (destSel.options.length == 0)
//------------ Risetto la lista dei figli
chgFiglio(firstValue);
} // function chgProv(aValue)
function chgFiglio(aValue) {
//--------- Svuoto la seconda select - IE only
var destSel = document.getElementById('sel3');
lenDest = destSel.options.length;
for (i=lenDest-1;i>=0;i--) {
destSel.remove(i);
} // for (i=lenDest-1;i>=0;i--)
//--------- Percorro l'array
lenArr = figli.length;
for (i=0;i<lenArr;i++) {
curLine = figli[i];
//-------- Cerco la prima virgola
posPVirg = curLine.indexOf(',');
//
if (curLine.substr(0,posPVirg) == aValue) {
curElement = curLine.substr(posPVirg+1,curLine.length);
//--------- Cerco la seconda virgola
posSVirg = curElement.indexOf(',');
oValue = curElement.substr(0,posSVirg);
oText = curElement.substr(posSVirg+1,curElement.length);
//--------- Creo l'opzione
var newOpt = document.createElement('OPTION');
ind = destSel.options.length;
destSel.options.add(newOpt,ind);
newOpt.value = oValue ;
newOpt.text = oText;
} // if (lenArr[i].substr(0,posPVirg-1) == aValue)
} // for (i=0;i<lenArr;i++)
//--------- Caso non trovo niente
if (destSel.options.length == 0) {
var newOpt = document.createElement('OPTION');
ind = destSel.options.length;
destSel.options.add(newOpt,ind);
newOpt.value = '' ;
newOpt.text = '----------------------';
} // if (destSel.options.length == 0)
} // function chgCom(aValue)
var padri = new Array();
indice = 0;
var figli = new Array();
indice2 = 0;
//------------ Qui generi i padri con MYSQL combinando :
// l'ID del nonno
// l'ID del padre
// Il nome del padre
//-------- IL NONNO E' : ALCIDE
padri[indice++]= "0,3,Padre ADRIANO";
padri[indice++]= "0,4,Padre ALESSANDRO";
padri[indice++]= "0,1,Padre ANGELO";
padri[indice++]= "0,2,Padre ARTURO";
//-------- IL NONNO E' : ERMENEGILGO
padri[indice++]= "1,6,Padre ELVIO";
padri[indice++]= "1,5,Padre EMILIO";
//-------- IL NONNO E' : MODESTO
padri[indice++]= "2,12,Padre MARCELLO";
padri[indice++]= "2,22,Padre MARCO";
padri[indice++]= "2,8,Padre MICHELLE";
padri[indice++]= "2,9,Padre MIRKO";
padri[indice++]= "2,55,Padre MORENO";
//------------ Qui generi i figli con MYSQL combinando :
// l'ID del padre
// l'ID del figlio
// Il nome del figlio
//-------- IL PADRE E' : ADRIANO
figli[indice2++]= "3,2,Figlio ALANO";
figli[indice2++]= "3,123,Figlio ACHILLE";
figli[indice2++]= "3,1,Figlio ALBERTO";
//-------- IL PADRE E' : ALESSANDRO
figli[indice2++]= "4,21,Figlio ADALBERTO";
figli[indice2++]= "4,125,Figlio ACARIO";
//-------- IL PADRE E' : ANGELO
figli[indice2++]= "1,212,Figlio AGOSTINO";
//-------- IL PADRE E' : ARTURO
figli[indice2++]= "2,2,Figlio ALBANO";
figli[indice2++]= "2,123,Figlio ALCESTE";
//-------- IL PADRE E' : ELVIO
figli[indice2++]= "6,131,Figlio ELIA";
figli[indice2++]= "6,132,Figlio ERNESTO";
//-------- IL PADRE E' : EMILIO
figli[indice2++]= "5,141,Figlio EDOARDO";
figli[indice2++]= "5,142,Figlio EGIDIO";
figli[indice2++]= "5,146,Figlio ENEA";
//-->
</script>
</head>
<body>
<select onchange="chgPadre(this.value)">
<option value=".">Seleziona un valore</option>
<option value="0">Nonno ALCIDE</option>
<option value="1">Nonno ERMENEGILGO</option>
<option value="2">Nonno MODESTO</option>
</select>
<select name="sel2" id="sel2" onchange="chgFiglio(this.value)">
<option>----------------------</option>
</select>
<select name="sel3" id="sel3">
<option>----------------------</option>
</select>
</body>
</html>