piixeldesigns
asked on
Filter select option for state then suburb then postcode
Hello All,
I have a quick question with my website. I have a registration form which has the following drop down options:
- State (Australian States)
- Suburbs
- Postcodes
I need the Suburb to be filtered by the state, so if you select say NSW, the suburbs dropdown will then populate with all of the suburbs that are listed in the state NSW, then depending which suburb they choose it will display the postcode for that specific suburb. The postcode dropdown should be populated depending on the choice of suburb.
Here is my code currently, by I am confused with what to do next on how to get the above to work:
Thanks In Advance!
PD
I have a quick question with my website. I have a registration form which has the following drop down options:
- State (Australian States)
- Suburbs
- Postcodes
I need the Suburb to be filtered by the state, so if you select say NSW, the suburbs dropdown will then populate with all of the suburbs that are listed in the state NSW, then depending which suburb they choose it will display the postcode for that specific suburb. The postcode dropdown should be populated depending on the choice of suburb.
Here is my code currently, by I am confused with what to do next on how to get the above to work:
<tr>
<td class="reg">State</td>
<td class="reg">
<?php
$state_query="select distinct(sp_state) from tbl_state_postals order by sp_state";
$state_result = mysql_query ($state_query);
echo '<select name=ddlState id=ddlState class=RegnForm><option value=0>Select State</option>';
while($nt=mysql_fetch_array($state_result))
{
echo "<option value=$nt[sp_state]>$nt[sp_state]</option>";
$nt['sp_state'];
if ($searchtypepropsearch == "ressale") { echo 'selected="selected"'; } else { echo ""; }
}
echo "</select>";
//var_dump($nt['sp_state']);
//echo $nt;
?></td>
</tr>
<tr>
<td class="reg">Suburb</td>
<td class="reg">
<?php
$query="select sp_id,sp_suburbname from tbl_state_postals order by sp_suburbname";
$result = mysql_query ($query);
echo "<select name=ddlSuburb id=ddlSuburb class=RegnForm><option value=0>Select Suburb</option>";
while($nt=mysql_fetch_array($result))
{
echo "<option value=$nt[sp_suburbname]>$nt[sp_suburbname]</option>";
}
echo "</select>";
?></td>
</tr>
<tr>
<td class="reg">Postcode</td>
<td class="reg">
<?php
$postcode_query="select sp_id,sp_postalcode from tbl_state_postals order by sp_postalcode";
$postcode_result = mysql_query ($postcode_query);
echo "<select name=ddlPostcode id=ddlPostcode class=RegnForm><option value=0>Select Postcode</option>";
while($nt=mysql_fetch_array($postcode_result))
{
echo "<option value=$nt[sp_postalcode]>$nt[sp_postalcode]</option>";
}
echo "</select>";
?></td>
</tr>
Thanks In Advance!
PD
ASKER
I was thinking along this path but to preload all of the postcodes/zipcodes in Australia slows down my page by A LOT! hence why I was thinking of doing it the other way if possible?
Thanks!
Thanks!
To poplute another selectbox from another you would need to submit the for or use ajax.
I personaly like the use of javascript and ajax.
I personaly like the use of javascript and ajax.
ASKER
That sounds great and I have seen some examples of this however I have some other fields above the state,suburb and postcodes so how do I submit the form if it already has a <form above?
I am just a little confused with how this should be setup?
Thanks
I am just a little confused with how this should be setup?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help!!!
If I were designing this, I would ask for the ZIP code first and use it to infer the city and state. Maybe you could do something like that with your post codes.