Forum: Ruby on Rails How to give onchange for select_year rails helper....

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
m. j. (Guest)
on 2009-01-28 13:37
<%=select_year(Date.today,:include_blank=>true, :start_year =>
Date.today.strftime("%Y").to_i, :end_year => 1999)%>


i am using rhis helper... now i want to give onchange here....

Please help me to solve this ....




thanks in advance
JK
Luke P. (Guest)
on 2009-01-29 10:13
rails and rails only wrote:
> <%=select_year(Date.today,:include_blank=>true, :start_year =>
> Date.today.strftime("%Y").to_i, :end_year => 1999)%>
>
> i am using rhis helper... now i want to give onchange here....

If you check out the api:

http://api.rubyonrails.org/classes/ActionView/Help...

select_year(date, options = {}, html_options = {})

So to add an onchange you need to use the html_options hash...

<%=select_year(Date.today,{:include_blank=>true, :start_year =>
Date.today.strftime("%Y").to_i, :end_year => 1999}, {:onchange =>
'myjsfunction();'})%>

Note the curly braces.  Ruby is pretty clever in that it will convert
the last set of symbols into a hash which is pretty helpful but not if
you want be able to send the html_options hash.  However if you
specifically mark the hashes (i.e. put curly braces around them) you can
send both hashes.

Cheers
Luke
This topic is locked and can not be replied to.