Edit: a, b, c are objects.
I have an erb file as follows with a, b, c variables.
<script type="text/javascript">
function fun(a,b,c){
console.log(a);
console.log(b);
console.log(c);
}
</script
<% a %>
<% b %>
<% c %>
<input type="checkbox" id="group_box" onclick="fun(a,b,c);"/>
But either the variable gets passed as string or it throws Invalid or Unexpected token error.
What am I doing wrong?
This is all I have tried so far -
onclick = "fun(a, b, c)"onclick = "fun('a, b, c')"onclick = "fun(\'' + a + '\', \'' + b + '\', \'' + c + '\')"onclick = "fun(\'' + <%= a %> + '\', \'' + <%= b %> + '\', \'' + <%= c %> + '\')"
TIA
const a = <%= a %>; function fun(a, b, c) { ... };with the caveat that the value needs to be JS-escaped/-quoted. Or you can render JSON, etc. There's several options--try #4 was the closest, but you need to look at the rendered output to see what may have gone wrong. It also matters how the data is being passed to the view layer, e.g., instance variables like@aor some other mechanism.