Forum: Ruby on Rails called javascript method and ruby method with 1 button?

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.
Lalala L. (Guest)
on 2007-04-22 14:06
Hi

I create a javascript method in rhtml with <script> function js()
</script>
and I would like to have 1 button that will call my controller method
and js() at the same time, so user will only need to click 1 button
instead of 2

Is this possible to do?

Thank you
MichaelLatta (Guest)
on 2007-04-22 19:31
(Received via mailing list)
You can use the link_to_function helper to setup the call to JS or
just use straight js to do that.  Inside your js function use
Ajax.Request or one of its subclasses to call the controller action
using XmlHttpRequest.

Michael

On Apr 22, 3:06 am, Lalala L. <removed_email_address@domain.invalid>
Chris M. (Guest)
on 2007-04-28 15:26
(Received via mailing list)
You can use button_to_function with remote_function to create a button
that will use Ajax to call an action in your controller.

The method remote_function takes the same parameters as
link_to_remote, which means that you can then use parameters
like :before, :after, :complete, etc. to call arbitrary JavaScript at
various points during the Ajax request.

For example:

<%= button_to_function("Click me", remote_function(:url => {:action
=> :do_stuff}, :before => "myJavaScriptFunction()")) %>

Chris

On Apr 22, 11:06 am, Lalala L. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.