# Add onchange or onclick to field in select

**URL:** <https://www.ruby-forum.com/t/add-onchange-or-onclick-to-field-in-select/132977>\
**Category:** Rails\
**Created:** [March 26, 2008, 11:43am UTC](https://www.ruby-forum.com/t/add-onchange-or-onclick-to-field-in-select/132977 "2008-03-26T11:43:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [March 26, 2008, 11:43am UTC](https://www.ruby-forum.com/t/add-onchange-or-onclick-to-field-in-select/132977/1 "2008-03-26T11:43:17Z")

</div>

Hello  
I’d like to make a list of items and then when an item is clicked, I  
display the “edit” view, something like  
@items = Item.find(:all)  
\<%= select ‘my\_items’, select\_options(@items), :onchange =\>  
remote\_function(edit\_item\_path(item)) %\>  
How can I pass only the clicked Item to the edit view :  
edit\_item\_path(item)

thanks

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [March 26, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/add-onchange-or-onclick-to-field-in-select/132977/2 "2008-03-26T16:18:39Z")

</div>

I’m using the following:

:onChange =\> remote\_function(:url =\> {:action =\>  
‘choose\_stylist’}, :with =\> “‘stylist=’ + value”)

You might be able to do this:

:onChange =\> remote\_function(edit\_item\_path, :with =\> “‘item=’ +  
value”)

You might need to set up ‘edit\_item’ in your controller to use  
params[:item] in this case - I’m not sure. I think that the ‘:with =\>  
stuff’ is what you need, though.

-Kyle

On Mar 26, 5:43 am, “Abir B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [March 27, 2008, 9:52am UTC](https://www.ruby-forum.com/t/add-onchange-or-onclick-to-field-in-select/132977/3 "2008-03-27T09:52:44Z")

</div>

Kyle wrote:

> I’m using the following:
> 
> :onChange =\> remote\_function(:url =\> {:action =\>  
> ‘choose\_stylist’}, :with =\> “‘stylist=’ + value”)
> 
> You might be able to do this:
> 
> :onChange =\> remote\_function(edit\_item\_path, :with =\> “‘item=’ +  
> value”)
> 
> You might need to set up ‘edit\_item’ in your controller to use  
> params[:item] in this case - I’m not sure. I think that the ‘:with =\>  
> stuff’ is what you need, though.
> 
> -Kyle
> 
> On Mar 26, 5:43 am, “Abir B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

The problem is that edit\_item\_path require an id, and must be written  
edit\_item\_path(id) so can someone tell me how change the route  
edit\_item\_path so that It does’nt require this param??  
thanks

---

<div class="post-metadata">

**Author:** ![abir84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@abir84](https://www.ruby-forum.com/u/abir84)\
**Post date:** [March 27, 2008, 11:20pm UTC](https://www.ruby-forum.com/t/add-onchange-or-onclick-to-field-in-select/132977/4 "2008-03-27T23:20:58Z")

</div>

I wonder if it might be as simple as this:

:onChange =\> remote\_function(edit\_item\_path(value))

?

-Kyle

On Mar 27, 3:52 am, “Abir B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
