How to Trigger 'onclick' or 'onchange' on <select>

I have two dropdowns 'a' and 'b'. when something is selected on 'a',
its onchange event has an action and an update area which works fine.

but when it comes to editing a record, i am able to list items in 'a'
dropdown and select the current value but this leave 'b' dropdown empty.

i would like to trigger an onchange or onclick event for 'a's selected
value so that 'b' drop down is populated correctly.

any ideas?

This is easily a dhtml issue, or one that can likely be performed in
rjs. (repopulating 'b') when someting occurs. Additionally, here is
working code I use to pick up when a dropdown's selection has changed:

<% form_for :channels, :html => {:name => 'channelsform'},:url=>
{ :action =>"newchannel", :controller =>"channels"} do |f| %>
    <%= f.label "Channel" %>
  <%= select("channel", "id", Channel.find(:all, :order => 'channel
ASC', :conditions => ['deleted=0']).collect {|p| [ p.channel,
p.id ]}, { :include_blank => true}, { :onchange =>
"document.channelsform.submit();"}) %>
  <input type="hidden" name="minimenu" value="<%= @minimenu %>" />
<%end%>

It;s a little polluted with real-world dictates, but I dont want to
hack things out for trhis example and give you a broken example
inadvertently. The meat occurs in the :onchange where the form is
submitted in this case (when the user changes their selection).
Incidentally, this occurs in a partial, which then executes the
Channelscontroller.newchannel method. Perhaps you make a partial
holding dropdown 'b' and repopulate it in such a method? That should
work fine -Janna B

Rails List wrote:

I have two dropdowns 'a' and 'b'. when something is selected on 'a',
its onchange event has an action and an update area which works fine.

but when it comes to editing a record, i am able to list items in 'a'
dropdown and select the current value but this leave 'b' dropdown empty.

i would like to trigger an onchange or onclick event for 'a's selected
value so that 'b' drop down is populated correctly.

any ideas?

You can use observe_field which observe 'a' select tag and change the
values of 'b'.

Example :
select_tag "country", "<option>XYZ</option>"

observe_field 'country',:url => { :controller => 'location', :action =>
'location_chooser' },:on => 'click', :with => :q

google more on observe_field and select_tag.