Ciao a tutti,
ho trovato uno script che forse fa al caso mio, però non riesco a farlo funzionare:
Javascript
codice:
<script type="text/javascript" src="./js/ajax.js"></script>
<script type="text/javascript">
var ajax = new Array();
function getConducente(sel)
{
var countryCode = sel.options[sel.selectedIndex].value;
document.getElementById('conducenti').options.length = 0; // Empty city select box
if(countryCode.length>0){
var index = ajax.length;
ajax[index] = new sack();
ajax[index].requestFile = 'conducentiselect.php?ragione_sociale='+ragione_sociale; // Specifying which file to get
ajax[index].onCompletion = function(){ creaConducenti(index) }; // Specify function that will be executed after
//file has been found
ajax[index].runAJAX(); // Execute AJAX function
}
}
function creaConducenti(index)
{
var obj = document.getElementById('clienti');
eval(ajax[index].response); // Executing the response from Ajax as Javascript code
}
</script>
XHTML
codice:
<form action="" method="post">
<table>
<tr>
<td><select id="clienti" name="clienti" onchange="getConducente(this)" multiple>
<?php
$exp = mysql_query("SELECT ragione_sociale FROM clienti ORDER BY ragione_sociale;");
while($cliente=mysql_fetch_array($exp)){
print("<option value='".$cliente["ragione_sociale"]."'>".$cliente["ragione_sociale"]."</option>");
} ?>
</select>
</td>
</tr>
<tr>
<td><select id="conducenti" name="conducenti" multiple>
</select>
</td>
</tr>
<tr>
<td><select id="flotta" name="flotta" multiple>
<?php
$exp3 = mysql_query("SELECT * FROM flotta ORDER BY targa;");
while($flotta=mysql_fetch_array($exp3)){
print("<option value='".$flotta["targa"]."'>".$flotta["targa"]." - ".$flotta["modello"]." - ".$flotta["versione"]."</option>");
} ?>
</select>
</td>
</tr>
</table>
</form>
PHP
Codice PHP:
<?php
$exp2 = mysql_query("SELECT * FROM conducenti WHERE ragione_sociale = '".$_GET["ragione_sociale"]."';");
while($conducente=mysql_fetch_array($exp2)){
print("<option value='".$conducente["conducente"]."'>".$conducente["conducente"]."</option>");
}
?>
Mi sapere indicare l'errore?