# Select and passing some javascript

**URL:** <https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924>\
**Category:** Rails\
**Created:** [December 2, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924 "2007-12-02T23:18:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [December 2, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924/1 "2007-12-02T23:18:32Z")

</div>

Hello,

After reading and reading the documentation, I can’t append some  
javascript function into a select.

It’s not possible ?

## documentation:

select(object, method, choices, options = {}, html\_options = {})

## some code:

return select(:id, :year, [[‘2008’, 2008],  
[‘2007’, 2007],  
[‘2006’, 2006]], :selected =\> session[:user\_year], :onChange =\>  
‘enterprise\_function();’ )

## what I want:
2007 2006 2005

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [December 3, 2007, 12:10am UTC](https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924/2 "2007-12-03T00:10:38Z")

</div>

On 2 Dec 2007, at 22:18, Raimon Fs wrote:

> ## some code:
> 
> return select(:id, :year, [[‘2008’, 2008],  
> [‘2007’, 2007],  
> [‘2006’, 2006]], :selected =\> session[:user\_year], :onChange  
> =\>  
> ‘enterprise\_function();’ )

I believe you want

> select(:id, :year, [[‘2008’, 2008],  
> [‘2007’, 2007],  
> [‘2006’, 2006]], {:selected =\>  
> session[:user\_year]}, :onChange =\>  
> ‘enterprise\_function();’ )

Fred

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [December 3, 2007, 8:44am UTC](https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924/3 "2007-12-03T08:44:10Z")

</div>

Frederick C. wrote:

> I believe you want
> 
> > select(:id, :year, [[‘2008’, 2008],  
> > [‘2007’, 2007],  
> > [‘2006’, 2006]], {:selected =\>  
> > session[:user\_year]}, :onChange =\>  
> > ‘enterprise\_function();’ )

thanks, it works …

## so, reading in the docs:

select(object, method, choices, options = {}, html\_options = {})

you put the onChange… between curly braces {} in the options, and what  
can we put in the html\_options {}

thanks !

raimon

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [December 3, 2007, 10:17am UTC](https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924/4 "2007-12-03T10:17:38Z")

</div>

On Dec 3, 7:44 am, Raimon Fs [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## so, reading in the docs:
> 
> select(object, method, choices, options = {}, html\_options = {})
> 
> you put the onChange… between curly braces {} in the options, and what  
> can we put in the html\_options {}

It’s the other way round. The first hash is options, which takes  
selected and a few other things. The second hash (html\_options) goes  
straight out to the rendered html, so if you put ‘foo’ =\> ‘bar’ then  
your select tag would have foo=“bar” as an attribute.

Fred

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [December 3, 2007, 10:29am UTC](https://www.ruby-forum.com/t/select-and-passing-some-javascript/121924/5 "2007-12-03T10:29:48Z")

</div>

Frederick C. wrote:

> On Dec 3, 7:44 am, Raimon Fs [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ## so, reading in the docs:
> > 
> > select(object, method, choices, options = {}, html\_options = {})
> > 
> > you put the onChange… between curly braces {} in the options, and what  
> > can we put in the html\_options {}
> 
> It’s the other way round. The first hash is options, which takes  
> selected and a few other things. The second hash (html\_options) goes  
> straight out to the rendered html, so if you put ‘foo’ =\> ‘bar’ then  
> your select tag would have foo=“bar” as an attribute.
> 
> Fred

ok, now I understand …

thanks again!

raimon
