msaggar
msaggar

Reputation: 45

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!

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

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

Upvotes: 0

Views: 367

Answers (1)

Joshua Moore
Joshua Moore

Reputation: 24776

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( ${studentInstance.id})"

Upvotes: 1

Related Questions