Dropdown list problem

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Eddy Parera
Posts: 18
Joined: Mon Feb 06, 2012 7:54 pm

Dropdown list problem

Post 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>";
      
?>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Dropdown list problem

Post by Jackolantern »

Do you want this to happen without a refresh? If so, PHP won't do it, so you would need Javascript.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”