1

Im trying to invoke a javascript method in a hyperlink onClick setting a parameter in JSTL as below :

<c:if test="${not test1 && test2}">
    <div class="alert alert-danger" role="alert">Message....
      <a onclick="executeBusinessPatch(<c:out value="${paymentId}"/>)" style="color: #a94442"><b>Configure Now.</b> 
      </a>
    </div>
</c:if>

 function executeBusinessPatch(inAppPaymentTenderId) {
  alert(inAppPaymentTenderId);
 }

But im getting above error Uncaught SyntaxError: Invalid or unexpected token when the hyperlink is clicked. What could be gone wrong?

GeekySelene
  • 847
  • 3
  • 13
  • 31

1 Answers1

1
onclick="executeBusinessPatch(<c:out value="${paymentId}"/>)" 

You have to use ' instead of " when using inline javascript:

onclick="executeBusinessPatch(<c:out value='${paymentId}'/>)" 

Otherwise it will treat the " at ..ue="${pay.. as the end of your string and continue parsing ${payment as were it the next attribute of your html element.

ThatBrianDude
  • 2,952
  • 3
  • 16
  • 42