how do i add onchange event here?
Framework: rails
Database: MySQL
am populating the options from the database and tat made me to use options_from_collection_for_select
select_tag(:variable,options_from_collection_for_select(:all, :id, :name))
thanks in advance.
views:
2747answers:
2
                +1 
                A: 
                
                
              select_tag takes an options hash as its final parameter, in which you can add any HTML attributes for the select. So to add an onchange attribute:
select_tag :variable, options_from_collection_for_select(:all, :id, :name), :onchange => 'your_onchange_handler()'
                  Daniel Vandersluis
                   2009-06-11 05:21:08
                
              will i be able to specify an action in a controller as an onchange event? if not, how do i do it then?
                  Nave
                   2009-06-11 05:22:20
                I'm not quite sure what you mean?
                  Daniel Vandersluis
                   2009-06-11 05:24:15
                i have an action in my controller to be executed and not a javascript event hander. will i be able able to do it with onchange event or are there any other ways?
                  Nave
                   2009-06-11 05:26:14
                DOM events can only fire javascript event handlers. You could have your event handler make an AJAX call to the action you want executed, though.
                  Daniel Vandersluis
                   2009-06-11 05:28:06
                can i get some code example for that?
                  Nave
                   2009-06-11 05:29:25
                I don't know exactly what you want to do of course, but take a look at the observe_field (http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001622) method -- you can use that instead of the above onchange handler to set up a Rails action to be called when an input is changed. Hopefully that will put you in the right direction!
                  Daniel Vandersluis
                   2009-06-11 05:37:05
                
                +1 
                A: 
                
                
              
            try something like:
:onchange => remote_function(:url => {:controller => 'controller', :action => 'action'})
                  marsjo
                   2010-07-24 03:09:38