# Pass selected value in combo as a parameter

**URL:** <https://www.ruby-forum.com/t/pass-selected-value-in-combo-as-a-parameter/194382>\
**Category:** Rails\
**Created:** [September 3, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/pass-selected-value-in-combo-as-a-parameter/194382 "2010-09-03T12:35:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfa-rero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@alfa-rero](https://www.ruby-forum.com/u/alfa-rero)\
**Post date:** [September 3, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/pass-selected-value-in-combo-as-a-parameter/194382/1 "2010-09-03T12:35:27Z")

</div>

Hi,

I have a select in my form:

\<%= select @issue\_type, “name”, @issue\_types.collect {|p| [p.name,  
p.id]} %\>

What I need to do is execute a method passing the value selected in the  
combo. I’ve tried lot of things, but I couldn’t.

@issue\_type is created in the controller and I assigned the first value  
in the collection. Of course, this is the value I only can pass.

To retrieve the value in the combo I’ve tried with onchange, but… I  
couldn’t make it work

Thanks in advance

---

<div class="post-metadata">

**Author:** ![alfa-rero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@alfa-rero](https://www.ruby-forum.com/u/alfa-rero)\
**Post date:** [September 6, 2010, 9:28am UTC](https://www.ruby-forum.com/t/pass-selected-value-in-combo-as-a-parameter/194382/2 "2010-09-06T09:28:39Z")

</div>

Again answering to myself…

I solved the problem by:

1-Using _link\_to\_remote_ using :with clause, and passing as serialize  
the id of the div that I had to create sourranding the select  
2-In the controller, once taked the parm and maked all the operations,  
use _respond\_to_ js and reloading the page.

Probably not the best solution… but it works!

---

<div class="post-metadata">

**Author:** ![alfa-rero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@alfa-rero](https://www.ruby-forum.com/u/alfa-rero)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/pass-selected-value-in-combo-as-a-parameter/194382/3 "2010-09-06T16:39:57Z")

</div>

What I usually do is get things working without Ajax first. Assuming  
you’ve done that, does onchange trigger anything in the logs? Using  
firebug or the developer tools in chrome/safari could tell you a lot  
too.

Luke

---

<div class="post-metadata">

**Author:** ![alfa-rero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@alfa-rero](https://www.ruby-forum.com/u/alfa-rero)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/pass-selected-value-in-combo-as-a-parameter/194382/4 "2010-09-06T16:39:30Z")

</div>

On 3 September 2010 11:35, Alfredo B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I have a select in my form:
> 
> \<%= select @issue\_type, “name”, @issue\_types.collect {|p| [p.name,  
> p.id]} %\>
> 
> What I need to do is execute a method passing the value selected in the  
> combo. I’ve tried lot of things, but I couldn’t.

Where are you trying to execute the method? In the browser or in the  
server? If in the browser then you will have to use javascript (in  
which case it is not really a Rails question), if in the server then  
put the select in a form and the selected value will be passed in  
params when the form is submitted.

Colin
