Scott Claerhout
2006-Mar-07 18:21 UTC
[Rails] how to add onchange javascript event to select field
I would like to add javascript ''onChange'' event handling for a
select
field, such as
<%= collection_select("job", "client_id" , @clients,
"id", "name") %>
with onChange="xxx"
Anyone know how to make this work?
Thank you,
Scott
--
Posted via http://www.ruby-forum.com/.
Berin Loritsch
2006-Mar-07 18:28 UTC
[Rails] how to add onchange javascript event to select field
Scott Claerhout wrote:> I would like to add javascript ''onChange'' event handling for a select > field, such as > <%= collection_select("job", "client_id" , @clients, "id", "name") %> > with onChange="xxx" > > Anyone know how to make this work? >http://rubyonrails.org/api/classes/ActionView/Helpers/FormOptionsHelper.html#M000352 The full API is: *collection_select*(object, method, collection, value_method, text_method, options = {}, html_options = {}) Just add :onchange => "xxx" to the html_options and you are set.
Scott Claerhout
2006-Mar-07 18:56 UTC
[Rails] Re: how to add onchange javascript event to select field
Berin,
Thank you for responding. I cannot get the syntax correct. Would it be
something like:
<%= collection_select("job", "client_id" , @clients,
"id", "name",
html_options = {:onchange => "alert(''hello'')"}
)%>
or
<%= collection_select("job", "client_id" , @clients,
"id", "name",
{:onchange => "alert(''hello'')"} )%>
Berin Loritsch wrote:> Scott Claerhout wrote:
>> I would like to add javascript ''onChange'' event
handling for a select
>> field, such as
>> <%= collection_select("job", "client_id" ,
@clients, "id", "name") %>
>> with onChange="xxx"
>>
>> Anyone know how to make this work?
>>
>
>
http://rubyonrails.org/api/classes/ActionView/Helpers/FormOptionsHelper.html#M000352
>
> The full API is:
>
> *collection_select*(object, method, collection, value_method,
> text_method, options = {}, html_options = {})
>
> Just add :onchange => "xxx" to the html_options and you are
set.
--
Posted via http://www.ruby-forum.com/.
Berin Loritsch
2006-Mar-07 19:00 UTC
[Rails] Re: how to add onchange javascript event to select field
Scott Claerhout wrote:> Berin, > Thank you for responding. I cannot get the syntax correct. Would it be > something like: > <%= collection_select("job", "client_id" , @clients, "id", "name", > html_options = {:onchange => "alert(''hello'')"} )%> > > or > > <%= collection_select("job", "client_id" , @clients, "id", "name", > {:onchange => "alert(''hello'')"} )%> >You have to get past the "options" parameter before you can use "html_options" <%= collection_select("job", "client_id" , @clients, "id", "name", {}, {:onchange => "alert(''hello'')"} )%>> > > Berin Loritsch wrote: > >> Scott Claerhout wrote: >> >>> I would like to add javascript ''onChange'' event handling for a select >>> field, such as >>> <%= collection_select("job", "client_id" , @clients, "id", "name") %> >>> with onChange="xxx" >>> >>> Anyone know how to make this work? >>> >>> >> http://rubyonrails.org/api/classes/ActionView/Helpers/FormOptionsHelper.html#M000352 >> >> The full API is: >> >> *collection_select*(object, method, collection, value_method, >> text_method, options = {}, html_options = {}) >> >> Just add :onchange => "xxx" to the html_options and you are set. >> > > >
Scott Claerhout
2006-Mar-07 20:37 UTC
[Rails] Re: Re: how to add onchange javascript event to select field
Berin, Thank you, that worked! Scott -- Posted via http://www.ruby-forum.com/.
know if there is a way to know the id or the customer has selected?? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
this will give you the selected text if you want it. you can probably
figure out what you need from this example.
var grain = $(''select#id_of_my_element
option:selected'').text();
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/BAM_jz5tsN8J.
For more options, visit https://groups.google.com/groups/opt_out.