multiple drop down Lists update on same form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tom.cull
Forum Commoner
Posts: 32
Joined: Tue Sep 06, 2005 9:31 am

multiple drop down Lists update on same form

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
Last edited by raghavan20 on Fri Sep 09, 2005 6:21 am, edited 1 time in total.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

That's sounds like client-side, take a look at codergoblin's tutorial:
viewtopic.php?t=29084
Post Reply