All:
I have setup the sample for the autofill drop down & xajax from this post:
This works fine without the need for database values. I can't generate values in any of the select boxes from the db table 'vehicles' that I created.
This is the table structure.
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL |auto_increment |
| vehYear | varchar(255) | YES | | NULL | |
| vehMake | varchar(255) | YES | | NULL | |
| vehModel | varchar(255) | YES | | NULL | |
| vehType | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
Display page(vehicles.php)
Function script(vehprocs.php)
Could someone explain what I am doing wrong?
Thank you.
I have setup the sample for the autofill drop down & xajax from this post:
This works fine without the need for database values. I can't generate values in any of the select boxes from the db table 'vehicles' that I created.
This is the table structure.
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL |auto_increment |
| vehYear | varchar(255) | YES | | NULL | |
| vehMake | varchar(255) | YES | | NULL | |
| vehModel | varchar(255) | YES | | NULL | |
| vehType | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
Display page(vehicles.php)
Code:
<?
include ('vehprocs.php');
require("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->registerFunction("vehMake");
$xajax->registerFunction("vehModel");
$xajax->registerFunction("vehType");
$xajax->processRequest();
?>
<html>
<head>
<title>Dynamic Select Boxes Using XAJAX</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" charset="utf-8" />
<? $xajax->printJavascript('xajax'); ?>
</head>
<body>
<form name="vehicles" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<span id="vehYear" id="selVehYear">
<tr>
<td>Please Choose Vehicle Year</td>
<!-- <td><select name="vehMake" id="vehMakeID" onChange="xajax_vehModel(this.value); document.getElementById('vehModel').style.display='block';">
<option value="2000">2000</option>
<option value="2002">2002</option>
<option value="2004">2004</option>
<option value="2006">2006</option>
<option value="2008">2008</option><option value="2009">2009</option>
</select>
</td> -->
<td><span id="selVehYear"> </span></td>
</tr>
</span>
<span id="vehMake" style="display:none;">
<tr>
<td>Please Choose Make</td>
<td><span id="selVehMake"> </span></td>
</tr>
</span>
<span id="vehModel" style="display:none;">
<tr>
<td>Please Choose Model</td>
<td><span id="selVehModel"> </span></td>
</tr>
</span>
<span id="vehType" style="display:none;">
<tr>
<td>Please Choose Type</td>
<td><span id="selVehType"> </span></td>
</tr>
</span>
</table>
</form>
</body>
</html>
Function script(vehprocs.php)
Code:
<?
function vehYear($key) {
$sql = 'SELECT vehYear FROM vehicles';
$dbserver = mysql_connect("localhost","root","");
$query = mysql_query($sql) or die (mysql_error());
$string = '<select name="vehYear" id="vehYearID">';
$string .= '<option value="none">Please choose a year</option>';
// $string .= '<option value="Sedan">Sedan</option>'; // remove this line
// $string .= '<option value="Sport Utility">Sport Utility</option>'; // remove this line
// $string .= '<option value="Convertible">Convertible</option>'; // remove this line
while ($row = mysql_fetch_assoc($query)) {
$string .= '<option value="' . $row['vehYear'] . '">' . $row['vehYear'] . '</option>';
}
$string .= '</select>';
$objResponse = new xajaxResponse();
$objResponse->assign("selVehYear","innerHTML",$string);
return $objResponse;
}
function vehMake($key) {
$sql = 'SELECT * FROM vehicles WHERE vehYear = {$key}';
$dbserver = mysql_connect("localhost","root","");
$query = mysql_query($sql) or die (mysql_error());
$string = '<select name="vehMake" id="vehMakeID" onChange="xajax_vehModel(this.value); document.vehicles.vehModel.style.display=\'block\';">';
$string = '<option value="none">Please choose vehicle make</option>';
// $string .= '<option value="Mercedes Benz">Mercedes Benz</option>'; // remove this line
// $string .= '<option value="Cadillac">Cadillac</option>'; // remove this line
// $string .= '<option value="Foreign">Foreign</option>'; // remove this line
while ($row = mysql_fetch_assoc($query)) {
$string .= '<option value="' . $row['vehMake'] . '">' . $row['vehMake'] . '</option>';
}
$string .= '</select>';
$objResponse = new xajaxResponse();
$objResponse->assign("selVehMake","innerHTML",$string);
return $objResponse;
}
function vehModel($key) {
$sql = 'SELECT * FROM vehicles WHERE vehMake = {$key}';
$dbserver = mysql_connect("localhost","root","");
$query = mysql_query($sql) or die (mysql_error());
$string = '<select name="vehModel" id="vehModelID" onChange="xajax_vehType(this.value); document.vehicles.vehType.style.display=\'block\';">';
$string .= '<option value="none">Please choose vehicle model</option>';
// $string .= '<option value="CLS 55">CLS 55</option>'; // remove this line
// $string .= '<option value="Escalade Hybrid">Escalade Hybrid</option>'; // remove this line
// $string .= '<option value="Aston Martin DB9">Aston Martin DB9</option>'; // remove this line
while ($row = mysql_fetch_assoc($query)) {
$string .= '<option value="' . $row['vehModel'] . '">' . $row['vehModel'] . '</option>';
}
$string .= '</select>';
$objResponse = new xajaxResponse();
$objResponse->assign("selVehModel","innerHTML",$string);
return $objResponse;
}
function vehType($key) {
$sql = 'SELECT * FROM vehicles WHERE vehModel = {$key}';
$dbserver = mysql_connect("localhost","root","");
$query = mysql_query($sql) or die (mysql_error());
$string = '<select name="vehType" id="vehTypeID">';
$string .= '<option value="none">Please choose vehicle type</option>';
// $string .= '<option value="Sedan">Sedan</option>'; // remove this line
// $string .= '<option value="Sport Utility">Sport Utility</option>'; // remove this line
// $string .= '<option value="Convertible">Convertible</option>'; // remove this line
while ($row = mysql_fetch_assoc($query)) {
$string .= '<option value="' . $row['vehType'] . '">' . $row['vehType'] . '</option>';
}
$string .= '</select>';
$objResponse = new xajaxResponse();
$objResponse->assign("selVehType","innerHTML",$string);
return $objResponse;
}
?>
Could someone explain what I am doing wrong?
Thank you.