# How to give onchange for select\_year rails helper

**URL:** <https://www.ruby-forum.com/t/how-to-give-onchange-for-select-year-rails-helper/158820>\
**Category:** Rails\
**Created:** [January 28, 2009, 12:37pm UTC](https://www.ruby-forum.com/t/how-to-give-onchange-for-select-year-rails-helper/158820 "2009-01-28T12:37:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjayakumar2k6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mjayakumar2k6](https://www.ruby-forum.com/u/mjayakumar2k6)\
**Post date:** [January 28, 2009, 12:37pm UTC](https://www.ruby-forum.com/t/how-to-give-onchange-for-select-year-rails-helper/158820/1 "2009-01-28T12:37:30Z")

</div>

\<%=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

---

<div class="post-metadata">

**Author:** ![mjayakumar2k6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mjayakumar2k6](https://www.ruby-forum.com/u/mjayakumar2k6)\
**Post date:** [January 29, 2009, 9:13am UTC](https://www.ruby-forum.com/t/how-to-give-onchange-for-select-year-rails-helper/158820/2 "2009-01-29T09:13:34Z")

</div>

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:

> **[ActionView::Helpers::DateHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001489)**
>
> Action View Date Helpers The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time elements.

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
