I have the following code sample which was written in the JSP. But it is not working. I have tried that code snippet from the following links. But it didn't help me to solve the problem.
Pass a JSP variable as parameter to javascript function
Passing Jsp variable to javascript as a function parameter
< c:forEach items="${items}" var="item">
<div onclick="myOnClick('<%=item%>')">${item.title}</div>
< /c>
function myOnClick(item){
console.log(JSON.stringify(item));
}
Actually I am getting an error in the eclipse that "item cannot be resolved to a variable" for the JSP code.
I tried the below one code
<div onclick="myOnClick(${item})">${item.title}</div>
It was throwing "Syntax error:illegal character" error.
Need help to fix this issue. Thank you.