# Can you call multiple functions with onclick

**URL:** <https://www.ruby-forum.com/t/can-you-call-multiple-functions-with-onclick/84170>\
**Category:** Rails\
**Created:** [February 2, 2007, 12:14am UTC](https://www.ruby-forum.com/t/can-you-call-multiple-functions-with-onclick/84170 "2007-02-02T00:14:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 2, 2007, 12:14am UTC](https://www.ruby-forum.com/t/can-you-call-multiple-functions-with-onclick/84170/1 "2007-02-02T00:14:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 2, 2007, 1:20am UTC](https://www.ruby-forum.com/t/can-you-call-multiple-functions-with-onclick/84170/2 "2007-02-02T01:20:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 2, 2007, 1:22am UTC](https://www.ruby-forum.com/t/can-you-call-multiple-functions-with-onclick/84170/3 "2007-02-02T01:22:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9f8e36/32.png) [@kim](https://www.ruby-forum.com/u/kim)\
**Post date:** [February 2, 2007, 1:29am UTC](https://www.ruby-forum.com/t/can-you-call-multiple-functions-with-onclick/84170/4 "2007-02-02T01:29:37Z")

</div>

That Works! Thanks

On 2/1/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > there shouldn’t be a problem with that.
> > 
> > >
> 
> >

–  
Kim G.  
removed\_email\_address@domain.invalid

“We are all stakeholders in the Karma economy.”
