Questo il codice cho popola due select:
[INDENT] <html>
<head>
<title>Select doppia</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="it" />
<meta name="Robots" content="All" />
<script type="text/javascript">
var bluesplayers= new Array("B.B. King", "Muddy Waters", " Stevie Ray Vaughan", "George Thorogood");
var rockplayers = new Array("Alvin Lee", "David Gilmour", "Pete Townshend", "Jeff Beck");
function set_player() {
var select_genre = document.myform.genre;
var select_player = document.myform.player;
var selected_genre = select_genre.options[select_genre.selectedIndex].value;
select_player.options.length=0;
if (selected_genre == "blues"){
for(var i=0; i<bluesplayers.length; i++)
select_player.options[select_player.options.length] = new Option(bluesplayers*);
}
if (selected_genre == "rock"){
for(var i=0; i<rockplayers.length; i++)
select_player.options[select_player.options.length] = new Option(rockplayers*);
}
}
</script>
</head>
<body>
<h1>Select doppia</h1>
<form name="myform" method="POST">
<table>
<tr>
<td>Testo:</td><td><INPUT TYPE="text" NAME="username" SIZE="8" MAXLENGTH="8">
</td></tr>
<tr>
<td>Genre:</td><td>
<select name="genre" onchange="set_player()">
<option value="blues">Select One
<option value="blues">Blues
<option value="rock">Rock
</select>
</td>
</tr><tr>
<td>Guitarist:</td><td>
<select name="player">
<option>------
</select>
</td></tr>
</table>
</form>
</body>
</html>
[/INDENT]Io codice sopra funziona perfettamente se lo provi. Per prendere i dati dal db avrei bisogno di sapere se mysl-postgres... comunque qui un esempio in php-mysql:
function getparent($parentid,$title) {
global $dbi;
$result=sql_query("SELECT cid,parentcid,title FROM dw_archivio_categories WHERE cid='$parentid'", $dbi) or die("Query non valida getparent:" . sql_error());
list($cid, $pparentid, $ptitle) = sql_fetch_row($result, $dbi);
if ($ptitle!="") $title=$ptitle."/".$title;
if ($pparentid!=0) {
$title=getparent($pparentid,$title);
}
return $title;
}
//in altra funzione o flusso di codice:
$resultcat = sql_query("SELECT cid,parentcid,title,catlanguage FROM dw_archivio_categories ORDER BY cid", $dbi);
$numrows = sql_num_rows($resultcat, $dbi);
if ($numrows>0) {
echo "<select name='cat'>";
while($row2 = sql_fetch_array($resultcat,$dbi)) {
$cid2 = $row2['cid'];
$ctitle2 = $row2['title'];
$parentid2 = $row2['parentcid'];
$catlanguage = $row2['catlanguage'];
if ($parentid2!=0) $ctitle2 = getparent($parentid2,$ctitle2);
$cat = $cid2."-".$parentid2;
echo "<option value='$cat' $sel>$cat $ctitle2 - $catlanguage</option>";
}
echo "</select> ";
echo "<br><input type='submit' name='bttedit' value='"._EDITCAT."'>
<input type='submit' name='bttdel' value='"._DELCATEGORY."'> ";
}
Praticamente la tebella categorie ha un ID e un PARENT, attenzione $dbi è la variabile di connessione e sql_query si possono impostare per con prefisso pg_ o my_ in dase al tuo db. Infine le costanti come _DELCATEGORY sono definite in altro file di traduzione. Per cambiare in dinamico basta mettere "<select name="genre" onchange="set_player()">". Comunque spero che come esempio vada bene, se no scrivimi!
Danzisiweb