risolto così.
ajax:
codice:
<script type="text/javascript">
function changeSelect(str) {
if (str == "") {
document.getElementById("categoria").innerHTML = "<option value='*'>*</option>";
return;
}
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("categoria").innerHTML = "<option value='*'>*</option>";
document.getElementById("categoria").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","home.php?sid=" + str, true);
xmlhttp.send();
}
</script>
select:
Codice PHP:
<tr>
<td>Sezione:</td>
<td>
<select name="sezione" onchange="changeSelect(this.value);" id="sezione">
<option value="*">*</option>
<?php
foreach (selectSection () as $rowSection) {
echo "<option value='" . $rowSection['sezione_id'] . "'>" . $rowSection['sezione_nome'] . "</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Categoria:</td>
<td>
<select name="categoria" id="categoria">
</select>
</td>
</tr>
richiamo query:
Codice PHP:
if (isset($_GET['sid'])) {
$sid = $_GET['sid'];
$result = $config->getPdo()->query("SELECT * FROM categorie WHERE sezione_FK=" . $sid . " ORDER BY categoria_nome");
foreach ($result as $rowCat) {
echo "<option value='" . $rowCat['categoria_id'] . "'>" . $rowCat['categoria_nome'] . "</option>";
}
}
ho solo un problema: nn mi aggiunge l'asterisco come valore iniziale.
sapete come fare??