Page 1 of 1

Dropdown list problem

Posted: Thu Jul 05, 2012 2:15 pm
by Eddy Parera
I'm working on my register.php page and I want to do something like this: We have the username, etc, and after the password check, I want to put two/three dropdown lists. The problem is, I want the second droplist to get the options from the first one.

E.g: On the first dropdown list, I choose the country where I am, and on the second, I want to put the region where I am. If I choose Portugal on the country, I only want Portuguese regions, not the entire regions table from mysql.

But now, I don't know how to grab the results from the first dropdown list to refresh the options of the second dropdown list right after I choose the option on the first dropdown list.

I have this so far...

Code: Select all

<?php
      print "<select name='country' length='30'>";
      $country="SELECT * from country";
      $country2=mysql_query($country) or die("Could not select country");
      while ($country3=mysql_fetch_array($country2))
      {
        print "<option>$country3[name]</option>";
      }
      print "</select><br>";

      print "<select name='region' length='30'>";
      $region="SELECT * from country where ownedby = '$country3'";
      $region2=mysql_query($region) or die("Could not select country");
      while ($region3=mysql_fetch_array($region2))
      {
        print "<option>$region3[name]</option>";
      }
      print "</select><br>";
      
?>

Re: Dropdown list problem

Posted: Fri Jul 06, 2012 12:14 am
by Jackolantern
Do you want this to happen without a refresh? If so, PHP won't do it, so you would need Javascript.