Forum: Ruby on Rails How to set onclick function for select_tag?

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.
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2008-12-26 04:26
I want to use select_tag helper but how to set a onclick function? where
should I define this function?

thanks.
6a480fa2dbd6f2ca51ff4190d0f29d03?d=identicon&s=25 Ryan (Guest)
on 2008-12-26 06:18
(Received via mailing list)
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.
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2008-12-26 06:21
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?
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2008-12-26 06:50
(Received via mailing list)
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
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2008-12-26 09:04
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.
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2008-12-26 14:39
(Received via mailing list)
Zhao,

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

http://railscasts.com/

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