How to set onclick function for select_tag?


#1

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

thanks.


#2

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.


#3

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?


#4

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


#5

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.


#6

Zhao,

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

http://railscasts.com/

Cheers, Sazima