# Combobox population by means of JQuery and Ajax

**URL:** <https://www.ruby-forum.com/t/combobox-population-by-means-of-jquery-and-ajax/177536>\
**Category:** Rails\
**Created:** [October 19, 2009, 11:14pm UTC](https://www.ruby-forum.com/t/combobox-population-by-means-of-jquery-and-ajax/177536 "2009-10-19T23:14:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spitfire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spitfire](https://www.ruby-forum.com/u/spitfire)\
**Post date:** [October 19, 2009, 11:14pm UTC](https://www.ruby-forum.com/t/combobox-population-by-means-of-jquery-and-ajax/177536/1 "2009-10-19T23:14:23Z")

</div>

This is the view municipalities.js.erb I have:

\<% list\_opt = options\_from\_collection\_for\_select(@municipalities, :id,  
:name) %\>  
\<% puts list\_opt %\> #ok! list\_opt contains the options  
$(’#municipality\_id’).html(’\<%= list\_opt %\>’);

and this is the combobox in the view:  
…  
Comune   
…

if instead of ‘\<%= list\_opt %\>’ I manually assign the string

'Alagna

Albano AliceCastello Arborio ...' into list\_opt then the combo municipality\_id correctly works, if I use options\_from\_collection\_for\_select doesn't works (empy combobox) but that string is the same of options\_from\_collection\_for\_select

then why doesn’t work ? ☹

Thank you,  
Alessandro

---

<div class="post-metadata">

**Author:** ![spitfire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@spitfire](https://www.ruby-forum.com/u/spitfire)\
**Post date:** [October 19, 2009, 11:25pm UTC](https://www.ruby-forum.com/t/combobox-population-by-means-of-jquery-and-ajax/177536/2 "2009-10-19T23:25:53Z")

</div>

Solved 😃

I forgot escape\_javascript:

$(’#event\_municipality\_id’).html("\<%= escape\_javascript(opts) %\>");

bye,  
Alessandro
