I have a partial that renders a select box using the following method:
<%= collection_select 'type', 'id', @types, 'id', 'name', {:prompt => true}, {:onchange => remote_function( :loading => 'Form.Element.disable('go_button')', :url => '/sfc/criteria/services', :with => ''type_id=' + encodeURIComponent(value) + '&use_wizard=#{use_wizard}''), :class => 'hosp_select_buttons' } %>
This partial gets used 2 times on every page, but at one point I need to get the value of the first select box. Using:
$('type_id')
returns the second select box. Is there a way to find the first one easily? Should I fix this using javascript or by redoing my partial?
Note: the dropdowns do get rendered in separate forms.
Yes, each element does need a unique ID, the page probably also fails HTML validation. Also, unless these are in 2 different forms you’ll have a conflict with the CGI parameter name.
If they are in 2 different forms you can probably get away with just setting the :id as you posted, if they are the same form you need to abstract the parameter name too:
collection_select ‘type’, ‘id_wizard_#{use_wizard}’…