Log in

View Full Version : Linked dropdowns in registration


menoutdoors
09-06-2005, 04:08 AM
Hello,

Im working on a registration system that has 2 linked dropdown lists. These lists are used to select Country then region (i.e. United States / New york). Now, the site is targeting a world wide audience so I need to have 200+ countries and in the range of 1500 regions. This makes having 2 seperate non linked dropdowns unrealistic.

I have the dropdowns coded on a normal php page but I am having issues getting them into the registration.php and associated template. At this point im using a combination of js , php , mysql to populate the 2nd dropdown after the onchange event.

Here is my php code.


<SCRIPT language=JavaScript>
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dropdown.php?cat=' + val ;
}
</script>

<?


///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT name,cc FROM country order by name");
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
//if(isset($cat) and strlen($cat) > 0){
if (isset($_GET['cat'])) {

//create mysql query
$regionlookup = "SELECT DISTINCT name FROM region WHERE cc='".$_GET['cat']."'";
$quer=mysql_query($regionlookup);
}else{$quer=mysql_query("SELECT DISTINCT name FROM region order by name"); }
////////// end of query for second subcategory drop down list box ///////////////////////////

echo "<form method=post name=f1 action=''>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cc']==$_GET['cat']){echo "<option selected value='$noticia2[cc]'>$noticia2[name]</option>"."<BR>";}
else{echo "<option value='$noticia2[cc]'>$noticia2[name]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////

////////// Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[name]'>$noticia[name]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
echo "</form>";
?>


Is there anyway for me to incorporate this into the register.php script so that it will display these linked dropdowns during registration?

Thank you in advance.

Oreamnos
10-03-2005, 07:47 AM
any luck with this? would be a great hack!

GNDI
01-22-2006, 01:46 PM
This is the hack I'm looking for, but but I can't code myself :( anyone who have finished this one?

mikeclarke
01-22-2006, 03:08 PM
Everybody should need this for there profile. I would like to see county and state.