Forum: Ruby on Rails How to call a fuction on onclick event.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
688adcb98303f778e3171ab69e09c08c?d=identicon&s=25 Christy John (chryste)
on 2007-07-03 09:12
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
<%= %><input type="radio" name= "type"
                             value= <>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" %>
<script type="text/javascript">
function myfunc()

I have no clue on why this is happening and I believe someone can help
4c3acdc3d93f54cc7a7281780ec8a4ee?d=identicon&s=25 Shai Rosenfeld (shai)
on 2007-07-03 09:18
> <%= %><input type="radio" name= "type"
>                              value= <>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 output):

<input type="radio" name="type" value="<%= %>
onclick="myfunc();" />
688adcb98303f778e3171ab69e09c08c?d=identicon&s=25 Christy John (chryste)
on 2007-07-03 09:32
Thanks Shai,
That was the error. You saved my day.
This topic is locked and can not be replied to.