Thoughts, information and reflections about technology

Parenthesis in a Rails radio_button_tag was preventing onclick javascript from working.

I was working with some existing code where I needed to add an onclick javascript event.

I couldn’t even get an alert box to work. After a good bit of trial and error, I found the reason. I put in a line of radio button code from the www3 school’s try it and it worked. After closer inspection, I found that the original radio button had parenthesis.

The original code was

<%= radio_button_tag( :data_file, “cars”)”%>

I tried adding the onclick as

<%= radio_button_tag( :data_file, “cars”, false, onclick: “setFileType(‘Cars’);”)%>

That didn’t work. Based on the sample line of code that did work, I removed the enclosing parenthesis as follows.

<%= radio_button_tag :data_file, “cars”, false, onclick: “setFileType(‘Cars’);”%>

Now the code and developer (Me) are happy!!


Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact me
Amazon Disclosure

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to and affiliated sites.