# How to set onclick function for select\_tag?

**URL:** <https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374>\
**Category:** Rails\
**Created:** [December 26, 2008, 4:26am UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374 "2008-12-26T04:26:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 26, 2008, 4:26am UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374/1 "2008-12-26T04:26:13Z")

</div>

I want to use select\_tag helper but how to set a onclick function? where  
should I define this function?

thanks.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 26, 2008, 6:18am UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374/2 "2008-12-26T06:18:14Z")

</div>

I don’t think IE supports onlick on the select tag. You may want to  
look at setting the onclick for the options tags inside the select.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 26, 2008, 6:21am UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374/3 "2008-12-26T06:21:06Z")

</div>

Ryan wrote:

> I don’t think IE supports onlick on the select tag. You may want to  
> look at setting the onclick for the options tags inside the select.

Hi Ryan,

Can I let onclick refer to a function defined in the controller?

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 26, 2008, 6:50am UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374/4 "2008-12-26T06:50:59Z")

</div>

Zhao Yi wrote:

> Can I let onclick refer to a function defined in the controller?

In HTML it’s:

onclick=‘Ajax.Request(…)’

In Ruby that’s :onclick =\> ‘Ajax.Request(…)’, natch.

To get the … part, write remote\_function or link\_to\_remote into a web  
page and  
view its source. That will show you how to pack the Request arguments.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 26, 2008, 9:04am UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374/5 "2008-12-26T09:04:27Z")

</div>

Phlip wrote:

> In HTML it’s:
> 
> onclick=‘Ajax.Request(…)’
> 
> In Ruby that’s :onclick =\> ‘Ajax.Request(…)’, natch.
> 
> To get the … part, write remote\_function or link\_to\_remote into a web  
> page and  
> view its source. That will show you how to pack the Request arguments.
> 
> –  
> Phlip

Sorry I am new to rails and don’t understand your comments.  
I have a select box and I want whenever its value changed, other text  
field value will change accordingly. Could you please give me an example  
for this?

thanks.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 26, 2008, 2:39pm UTC](https://www.ruby-forum.com/t/how-to-set-onclick-function-for-select-tag/156374/6 "2008-12-26T14:39:07Z")

</div>

Zhao,

Take a look at the excelent screencasts by Ryan B. (specially  
episode #88 and others on AJAX, RJS and JQuery) at:

> **[Ruby on Rails Screencasts - RailsCasts](http://railscasts.com/)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Cheers, Sazima
