I'm trying to write some module code that will change the options in a select box based on the value that is selected in a different select box, for a Views exposed filter form. I have a Views exposed filter form that has a "State" and "County" filter and I want to update the "County" select box options based on the value that is selected from the "State" select box.

I'm trying to work within "hook_form_views_exposed_form_alter". In looking at what is available to work with, I can see, using var_dump($form) that all of the select options are available. I can also see that I can see the options for each individual form element by assigning $form['field_fieldname_value'] to a variable.

Based on all that, I have a few questions maybe some forum members can help me out with:

1) Can I find the value (not the default value) that the user selects from the selectbox from within this hook? If so, what is the syntax for doing so? If not, where should I be able to find the selected value and what is the correct syntax?

2) What is the correct syntax for assigning new #options to a select box from within "hook_form_views_exposed_form_alter"?

3) Is "hook_form_views_exposed_form_alter" called when a form value is changed so that I can update the options in a select box dynamically as the selected value of a different select box is changed? If not, where do I capture this information?

If anybody can point me to any code examples for similar functionality, that would also be much appreciated.

Comments

billp44ruby’s picture

I was able to accomplish this using jQuery.

jhalicea’s picture

Please post your fix, I need something like that. I have two select, if one select = to some choice (town) you can only select one choice (date) in another select. I'm going to do this inside of a webform.

If you can post it only for reference I would thank you. I'm currently learning JQuery. :)