3

I want to call a javascript function when flow enters into <c:if> block.

For example, I have below code:

<c:if test="${!empty errorMessage && !(fn:contains(errorMessage, 'generic'))}">
    <span> errorError occured<br />
    </span>
</c:if>

I need to invoke a JS function only when this <c:if> is true.

Please suggest how to achieve this.

0

1 Answer 1

6

You can include the <script> tag within the <c:if> block, something like this:

<c:if test="${!empty errorMessage && !(fn:contains(errorMessage, 'generic'))}">
    <span>
        errorError occured<br />
    </span>
    <script>
        alert("Calling my function ...");
        myFunction(); // this is a call to your function which must be defined in the <head> section or another JS file.
    </script>
</c:if>

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.