msaggar msaggar - 1 year ago 110
Javascript Question

Passing a field of a domain object into javascript function in grails

I want to pass a field of a domain object to a javascript function in my view.gsp (grails) , but I am getting a syntax error.

Here is my gsp and javascript - please let me know if you see the syntax error. Thanks!

<td><a href='#' data-toggle="popover" id="popoverID" onclick="function setID( ${})">${fieldValue(bean: studentInstance, field: "active")}</a></td>

<script type="text/javascript">
var id = 0;
function setID(userId){
console.log("userId: " + userId);
id = userId;

Answer Source

The issue is you have function in your onclick. You don't need it there. Remove it so your onclick looks like this:

onclick="setID( ${})"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download