Quote:
Originally Posted by mlseim
|
+1 for AJAX. Especially if your second and subsequential dropdowns are depending on the previous one (which I guess is the case, as Focus' are only made by Ford, so selecting a Toyota won't give that option?).
If you want to program it yourself rather then using mlseims link (haven't checked it to be honest), have the <select> perform a JavaScript function on change or something.
PHP Code:
<select name="make" id="make" onchange="checkmodels()">
<option value="Ford">Ford</option>
<option value="Toyota">Toyota</option>
</select>
Code:
<script>
function check_models() {
var make = getElementById('make').value;
// get AJAX request ready, bla bla bla
// send AJAX request to functions.php?action=checkmodels
// if AJAX response is good, change selectlist
document.getElementById('models').innerHTML = ajax.responseText;
Where the functions file loads the corresponding models based on the make
PHP Code:
switch($_GET['action'] {
case 'checkmodels':
$sql = "SELECT * from models WHERE make = '{$_GET['action']}';
/* perform query, load 1 return variable with the HTML you want outputted, so
* <select name="model">
* <option value="Focus">Focus</option>
* <option value="Carola">Carola</option>
* </select>
*/
echo $return;
break;
}
Right, this is by no way a tutorial, nor a definitive answer, just an outline of an AJAX request to show you that it really isn't that hard
Regards,
Martin