Can you call multiple functions with onclick

80 views
Skip to first unread message

Kim

unread,
Feb 1, 2007, 6:14:05 PM2/1/07
to Ruby on Rails: Talk
I have a radio button that I would like to call two functions with an
onclick: one is a js function the other a remote function

Can this be done and what is the correct syntax?

js function call
-----------------------
<%= radio_button_tag 'save',1, checked = true, :onclick => 'hide_div()
' %>

remote_function
-----------------------
<%= radio_button_tag 'save',1, checked = true, :onclick
=>remote_function(:update => "@mod",
:url => { :action => :unsave, :id => @mod}) %>

Tried
------------
<%= radio_button_tag 'save',1, checked = true, :onclick =>
'hide_div();remote_function(:update => "@mod",
:url => { :action => :unsave, :id => @mod}) ' %>

Doesn't work, neither functions are called

Thanks for you help - K

njmac...@gmail.com

unread,
Feb 1, 2007, 7:19:38 PM2/1/07
to rubyonra...@googlegroups.com
Try this:


<%= radio_button_tag 'save',1, checked = true, :onclick
=>'hide_div() ' + remote_function(:update => "@mod",

    :url => { :action => :unsave, :id => @mod}) %>

Because 'hide_div()' is a string and remote_function returns a string, there shouldn't be a problem with that.

-N

njmac...@gmail.com

unread,
Feb 1, 2007, 7:21:58 PM2/1/07
to rubyonra...@googlegroups.com
Sorry, that should, strictly speaking, be


<%= radio_button_tag 'save',1, checked = true, :onclick
=>'hide_div(); ' + remote_function(:update => "@mod",
    :url => { :action => :unsave, :id => @mod}) %>

(note the semi-colon) Most browsers would probably be able to handle the first one though.

Kim Griggs

unread,
Feb 1, 2007, 7:28:38 PM2/1/07
to rubyonra...@googlegroups.com
That Works! Thanks
--
Kim Griggs
kim.g...@gmail.com

"We are all stakeholders in the Karma economy."
Reply all
Reply to author
Forward
0 new messages