Jack Daniel
Jack Daniel

Reputation: 2467

JavaScript in Grails's GSP page

how I can run impromtu js code inside the grails g:if statement? I want to run Error alert windows or success alert window. my code is

<g:if test="${flash.error}">
    <g:javascript>invokePopup(${flash.error})</g:javascript>
</g:if>

and in my main.js

function invokePopup(message) {
   $.prompt(message);
}

nothing happened in this case and YES, a added main.js to ApplicationResources.groovy

Upvotes: 0

Views: 1745

Answers (1)

Joshua Moore
Joshua Moore

Reputation: 24776

Assuming that flash.error contains a String value the following line needs to change to avoid unexpected identifier errors.

<g:if test="${flash.error}">
    <g:javascript>invokePopup("${flash.error}")</g:javascript>
</g:if>

Notice that flash.error is now outputted inside quotes.

Upvotes: 2

Related Questions