Page 1 of 1

Drop down menu selection that limits option available in fld

Posted: Wed Oct 07, 2009 9:29 pm
by edawson003
I have a form that I would like users to select their country. If a user selects USA, then I would like my state drop down that also includes Canada provinces to only show US states only as selectable (and vis a vis, if Canada is slected). For all other countries other than USA or Canada, I would like an open text box for entering territories instead of the State/Province drop down. Any ideas how can set this up?

FYI, the options available in my Country and State drop downs are pulled from my mysql table. Here's a sample of the code:

Code: Select all

<?
                          $optiondropdwnquery = "SELECT  optionid, optionname FROM OptionsLib WHERE optiongroupid = 6";  
 $optionsavailresult = mysql_query($optiondropdwnquery); 
 $selectedValue = isset($country) ? $country : '';
 
  echo '<select name="country">' . "\n";
while ($row = mysql_fetch_array($optionsavailresult, MYSQL_ASSOC)) {
     echo '<option value="' . $row['optionid']. '" ' . ($row['optionid']== $selectedValue ? 'selected="selected"' : '') . '>' .  $row['optionname'] . '</option>' . "\n";
}
 
  echo '</select>'; 
  ?>

Re: Drop down menu selection that limits option available in fld

Posted: Thu Oct 08, 2009 12:09 pm
by desperado
your code only shows the country select.

Is your difficulty with the relationships within tables, or is it that you are looking to update these parameters "live" on your page?

Re: Drop down menu selection that limits option available in fld

Posted: Thu Oct 08, 2009 2:07 pm
by edawson003
I provided the code for my country select which shows how it is plugged in a mysql table to generate the available options. The code for the state select is similarly structured, so no need for me to inlude that tidbit of code here(...I think). I am looking to update the functionality on my site's form that would control what select options are available in my state dropdown (select) based on selection made in the country select. For example, when a user select US then I want only US states to be available under the state drop down and same concept for Canada when it is selected as the country. I've seen it done on many a site, so I know it is not impossible or rather exotic. So that's one objective I am trying to get clues on how to implement.

The next objective is for all other countries (not US or Canada), I want the state select to instead be replaced with a open text field.

The tricky part (for me that is) is for these proposed live form changes to take place while certain selections are being made on the form (not after the submit button is activated). How do I set up a triggering mechanism code-wise that would in real time update dependent form elements in the way I explained above?