1

I have anchor tag and on click of it I am trying to pass parameters into the function but I am getting the error uncaught ReferenceError: testbody is not defined.

<a onClick="editComment(<%= comment.body%>)">Edit Comment</a>

testbody is the value stores in db and its of type text. Strangely when I pass something which is integer then no error is shown.

1 Answer 1

3

If I remember you need to add quote marks like so around the erb.

<a onClick="editComment('<%= comment.body%>')">Edit Comment</a>
Sign up to request clarification or add additional context in comments.

1 Comment

be sure to use escape_javascript in case comment.body contains single or double quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.