I am trying to figure out how it would be possible to dynamically update the contents of select boxes (the drop down menus). Basically what I want to do is change the items available in one select box based on what is selected in another. For example say I had two select box, one for country and one for state. To start the country list is populated and the state list is empty and based on what the user chooses from the country list, the state one is filled accordingly. I am trying to figure out how to do this using Drupal 4.7.0 beta 3. I have seen tutorials on how to do it just using normal html/php/javascript (http://www.plus2net.com/php_tutorial/php_drop_down_list.php) but I would like to figure out how to do it using Drupal's Form API. Any help would be greatly appreciated. Thanks!
Comments
I'm doing this extensively
I'm doing this extensively in 4.6, but converting to the 4.7 form API shouldn't be too difficult.
In my case using 2 selects, the first is pre-populated with a list of companies and the second is a list of representatives for each company.
Using drupal_set_html_head, I output a client side JavaScript string to build an array for use by the second select. I then add an onchange event to the first select. Finally, I use hook_footer() to initially set the on load default value.
I tried to include some code examples, but Druapl misinterprets everything as malicious.
I also have trouble with
I also have trouble with this as well.
Can you include some code samples? (even for 4.6)
(I could include, js, and also total list of all e.g. companies)
BUT, I have trouble with that JS (filter.js) cannot identify the form element (this.form.*), since drupal gives name ="edit[foo]" to form_elements. And i could not make that JS accepts as input this.form.edit[foo].
My javascript syntax is like this: filter.js($filterpattern, this.form.edit[foo]).
How do you identify your form element for JS?
Can you please include some code samples how you do it?
Many thanks.
Keve.
Got It
Thanks Bacteria Man, you definitely pointed me in the right direction.
Keve: use document.getElementById('edit-blah') in your JS code.
Thanks.
Thanks. (I was missing this very first step for id) :)
Reply
Hi
I want to render form based on selection onclick,\
With out page refresh
Is it possble man