# How to call a fuction on onclick event

**URL:** <https://www.ruby-forum.com/t/how-to-call-a-fuction-on-onclick-event/108413>\
**Category:** Rails\
**Created:** [July 3, 2007, 9:12am UTC](https://www.ruby-forum.com/t/how-to-call-a-fuction-on-onclick-event/108413 "2007-07-03T09:12:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chryste](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@chryste](https://www.ruby-forum.com/u/chryste)\
**Post date:** [July 3, 2007, 9:12am UTC](https://www.ruby-forum.com/t/how-to-call-a-fuction-on-onclick-event/108413/1 "2007-07-03T09:12:32Z")

</div>

Hi all,

I’m using a set of radio buttons, which when selected will transfer the  
control to a javascript function. But the issue is that the javascript  
function isn’t triggered. Is there any error in my code?

Given below is the code.

\<% @types.each do |type|%\> #@types was declared in the controller  
\<%= type.name %\>\<input type=“radio” name= “type”  
value= \<%type.id\>onclick= “myfunc();”\>  
\<% end %\>

The above code is in a partial and the javascript function is in an  
rhtml page.

My javascript function

\<%= javascript\_include\_tag “prototype” %\>  
\<%= javascript\_include\_tag “defaults” %\>

I have no clue on why this is happening and I believe someone can help  
me.  
Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![chryste](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@chryste](https://www.ruby-forum.com/u/chryste)\
**Post date:** [July 3, 2007, 9:18am UTC](https://www.ruby-forum.com/t/how-to-call-a-fuction-on-onclick-event/108413/2 "2007-07-03T09:18:57Z")

</div>

> \<%= type.name %\>\<input type=“radio” name= “type”  
> value= \<%type.id\>onclick= “myfunc();”\>

… the way the code is pasted here on the forum, it seems there is an  
error with some spacings…(the onclick is the continuation of the value  
attribute, and there are no qoutes on value (as well as a ‘=’ to display  
the type.id output):

\<input type=“radio” name=“type” value="\<%= type.id %\>  
onclick=“myfunc();” /\>

---

<div class="post-metadata">

**Author:** ![chryste](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@chryste](https://www.ruby-forum.com/u/chryste)\
**Post date:** [July 3, 2007, 9:32am UTC](https://www.ruby-forum.com/t/how-to-call-a-fuction-on-onclick-event/108413/3 "2007-07-03T09:32:54Z")

</div>

Thanks Shai,  
That was the error. You saved my day.  
Chris
