function getXMLHTTP() {
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 getModel(idCar) {
var strURL="http://localhost/root509dir/Includes/model.php?idCar="+idCar;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {document.getElementById('modelCont').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
模型.php
if(isset($_GET['idCar'])){
$idCar = mysql_real_escape_string($_GET['idCar']);
}
$modelQR = mysql_query("SELECT *FROM model WHERE from_make = '$idCar'") or die(mysql_error());?>
<?php echo htmlentities(PUB_AN_MOD); ?><em>*</em>
<select name="carmodel" id="carmodel">
<option value="0">----------------</option>
<?php while($model = mysql_fetch_array($modelQR)){?>
<option value="<?php echo htmlentities($model['id_model']);?>">
<?php echo htmlentities($model['car_model']);?></option>
<?php }?>
</select>
汽车.php
<?php
$QRcars = mysql_query("SELECT *FROM car ORDER BY car_make") or die(mysql_error());
if(mysql_num_rows($QRcars)>0){?>
<select name="cars" id="cars" onchange="getModel(this.value);"><option value="0">-------------------</option>
<?php while($cars = mysql_fetch_array($QRcars)){?>
<option value="<?php echo htmlentities($cars['id_car']);?>">
<?php echo htmlentities($cars['car_make']);?></option>
<?php }?>
</select>
<?php }?>
<span id="modelCont">
<?php echo htmlentities(PUB_AN_MOD); ?><em>*</em>
<select name="model" id="model">
<option value="0">---------</option>
</select>
</span>