[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Using Javascript and PHP to Create Dynamic Drop Downs

Asked by EmpKent in PHP and Databases

Tags: php, dynamic

I am trying to create a dynamic drop down. What I want is a pull down that contains a list of countries that is queried from a table. Once the user selects a country, the next drop down will then contain all the regions that are associated with that country. I am quite familiar with PHP but not too much with Javascript. My code is posted below. Right now, the code just doesn't do anything. I have a list of the countries and when I select one, the fill_sub() function just doesn't do it's part.

If someone could please point out my errors, that would be so much help.

Here is the code:

<?PHP
include '/data/www/connect.include';
?>
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
function Fill_Sub()
{
         var country = document.FormName.country;
         var region = document.FormName.region;
      if( country.options[country.selectedIndex].value != 0 )
      {  
                region.length = 0;
         }
          <?PHP
          $query = "SELECT country FROM tblcountry order by country";
          $result = odbc_exec($connect, $query);
          while( $Row = odbc_fetch_array($Result) )
      {
               ?>
            if( country.options[country.selectedIndex].text == "<?PHP echo $Row[Country]; ?>" )
            {
                       <?PHP      
                  $Query2 = "SELECT region FROM tblcountry WHERE country = '$Row[Country]'";
                      $Result2 = odbc_exec($connect, $Query2);
                        $ctr = 0;
                  While( $Row2 = odbc_fetch_array($Result2) )
                  {
                               echo "region.options[$ctr] = new Option('$Row2[Region]')";
                               echo "region.options[$ctr].value = '$Row2[Region]'";
                               $ctr++;
                        }
                       ?>
                }
      <?PHP
        }
?>  
}
-->
</SCRIPT>
</HEAD>

<BODY>
 <FORM name="FormName" method="POST" action="">
  <TABLE>
   <TR>
    <TD>Country: <SELECT name="country" onchange="Fill_Sub();">
      <option selected>
      <?PHP
      $query = "SELECT * FROM tblcountry ORDER BY Name";
      $result = odbc_exec($connect, $query) or die ("Query Failed");
      for ($i = 0; $i < odbc_num_rows( $result ); ++$i)
      {
            $line = odbc_fetch_array($result);?>
            <option><?PHP echo $line[Name];
      }
      ?>
      </SELECT></TD>
          <TD>Region: <SELECT name="region">
      <option selected>
      <option>Select a country</SELECT></TD>
   </TR>
  </TABLE>
 </FORM>
</BODY>
</HTML>

Thank you for your help in advance.
 
Related Solutions
Keywords: Using Javascript and PHP to Create Dy…
 
Loading Advertisement...
 
[+][-]04/27/05 10:19 AM, ID: 13878435Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/27/05 11:05 AM, ID: 13878832Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/27/05 11:35 AM, ID: 13879140Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/27/05 11:40 AM, ID: 13879194Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/27/05 11:52 AM, ID: 13879281Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/05 08:36 AM, ID: 13927751Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/05 08:52 AM, ID: 13927927Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/04/05 09:57 AM, ID: 13928534Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/05 11:34 AM, ID: 13929348Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/04/05 11:36 AM, ID: 13929365Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/04/05 01:27 PM, ID: 13930446Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/05 01:31 PM, ID: 13930475Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/04/05 01:48 PM, ID: 13930657Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/05 01:54 PM, ID: 13930711Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Tags: php, dynamic
Sign Up Now!
Solution Provided By: Batalf
Participating Experts: 3
Solution Grade: A
 
[+][-]05/04/05 01:59 PM, ID: 13930749Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/05 02:01 PM, ID: 13930767Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/10/05 05:26 AM, ID: 13967567Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89