Page 1 of 1

multiple drop down Lists update on same form

Posted: Fri Sep 09, 2005 4:09 am
by tom.cull
Hi

i am creating a form and I want the fields to update based on a previous fields selection.

I have dropdown Lists(Car Make & Car Model) on same web form. This dropdwon List are primarily populated by the fields MySql datababse. I would like to query MySql database based on the selection i make in those dropdown lists. But the most important functionality i would like here is ie If i make my selection in Car Make list, i want the Car Model dropdown list to be automatically reupdated based on the Car Make selection.

can any one point me in the right direction ?

thanks

Posted: Fri Sep 09, 2005 4:19 am
by raghavan20
lets assume you have a select input control

Code: Select all

<form name = 'frmCars' method = 'post' action = '#'>
<select name = 'slCars' onchange = 'javascript:form.submit();'>
<option value = 'BMW'>BMW</option>
<option value = 'Jaguar'>Jaguar</option>
<option value = 'Bentley'>Bentley</option>
<option value = 'Mazda'>Mazda</option>
</select>
<select name = 'carModels'>

Code: Select all

<?php
$query = 'select models from Cars where car_id = {$_POST["slCars"]}'
$result = mysql_query($query);
if (is_resource($result)){
if(mysql_num_rows($result)){
while(row = mysql_fetch_row($result)){
echo "<option value = '{$row[0]}'>$row[0]</option>";
}
}
}
?>

Code: Select all

</select>
</form>
hope this works.
if you have got time, then you can try javascript with xmlhttp.

Posted: Fri Sep 09, 2005 5:58 am
by harrisonad
That's sounds like client-side, take a look at codergoblin's tutorial:
viewtopic.php?t=29084