Last Updated on November 29, 2019 by Christopher G Mendla
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!!