Skip to content

Instantly share code, notes, and snippets.

@juanm55
Created January 24, 2012 16:22
Show Gist options
  • Save juanm55/1670943 to your computer and use it in GitHub Desktop.
Save juanm55/1670943 to your computer and use it in GitHub Desktop.
interesting way of updating text field in rails... without ajax requests....
<%= select_tag("objective[indicator_id]", options_for_select([["seleccione indicador",0]] + @indicators.map {|u| [u.name,u.id]}, selected = var_indicator ) , html_options = {:onchange => "this.form.elements['objective[criteria]'].value = this.form.elements['tmp_objective[indicator_id]'].options[ this.form.elements['objective[indicator_id]'].selectedIndex ].text "}) %>
<%= text_area_tag "objective[criteria]", var_criteria.to_s , :rows => 5, :cols => 70 %></td>
<div style="display:none;VISIBILITY:none;" >
<%= collection_select("tmp_objective", "indicator_id" , @indicators, "id", "suggested_criteria", options ={:prompt=>""}) %>
</div>
@juanm55
Copy link
Author

juanm55 commented Jan 24, 2012

the idea is to select something in the select tag and fill the text area with some info from the DB....

so what is done: select something and have a js that looks up the selection id, in another collection_select (which has the needed information) and find the equivalent id there,,, and put the info into de text_area_tag...

hacky... weird... obstrusive... but works... with no additional actions added to controller, and is vanilla js...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment