7

Is there a way to call a javascript function inside an if with JSTL?

Here's the code

<c:choose>
                <c:when test="${orderUploadAction.errors.size()==0}">

                CALL JS FUNCTION HERE

                </c:when>
                <c:otherwise>

                CALL JS FUNCTION HERE

                </c:otherwise>
</c:choose>
David
  • 840
  • 6
  • 17
  • 37
  • 1
    Understand that your JSTL code runs on your server, and the JavaScript code won't run until the code reaches the client browser. When the JavaScript runs, there's nothing left of the JSTL code - it's just HTML/CSS/JavaScript. – Pointy Jan 13 '15 at 15:16

1 Answers1

13

Try this

<c:choose>
  <c:when test="${orderUploadAction.errors.size()==0}">
     <script> yourFunctionName() </script>
  </c:when>
  <c:otherwise>
     <script> yourAnotherFunctionName() </script>
  </c:otherwise>
</c:choose>
Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144