La prima select 'nation' popola dinamicamente la seconda select. Lo script pare funzionare, e la seconda select è popolata con successo. Quando però invio il modulo, i valori della seconda select non passano.
Ho provato ad inviare il modulo con get: non appare niente (regione=...), come se il contenuto del file esterno findregione.php non venisse letto. Cosa non va???
************* il codice javascript **************
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getState(name) {
var strURL="findregione.php?nation="+name;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('regiondiv').innerHTML=req .responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
**************** il codice html con le due select ****************
<select name="nation" id="nation" onChange="getState(this.value)">
<option >Select country</option>
[...]
</select>
<div id="regiondiv" name="regiondiv">
<select name="regione">
<option>Select region</option>
</select>
</div>
************* il file esterno findregione.php *******************
<? $nation=$_GET['nation'];
include_once 'connections.php';
dbConnect();
$query="SELECT [...]";
$result=mysql_query($query);
?>
<select name="regione">
<option>Select region</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value="<?=$row['nomeregione']?>"><?=$row['nomeregione']?></option>
<? } ?>
</select>