Reputation: 1
I am trying to set the id on a grails link, dynamically, using javascript. Is that even possible?
<g:link controller:"patient" action:"show" id:"patient0-id"/>
<script type="text/javascript">
var id = 20;
$("#patient0-id").attr("id", id);
</script>
Upvotes: 0
Views: 216
Reputation: 24776
No it's not possible since the Grails tag is processed server-side (before the page is rendered by the client) and JQuery/Javascript is processed client-side in the browser after the Grails tag has already been processed by the server. Thus, you can't use JQuery/Javascript to effect the Grails tag.
However, you could do something like this:
<a id="someLink" href="#">Something</a>
<script type="text/javascript">
var baseUrl = "${createLink(controller: 'someThing', action: 'someAction'}";
var id = 1234;
$("#someLink").attr("href", baseUrl+"/"+id);
</script>
Upvotes: 2