Kleber Mota Kleber Mota - 1 year ago 478
Javascript Question

Using thymeleaf variable in onclick attribute

In my current spring-boot project, I have one view with this html code:

<button type="button" class="btn btn-primary" onclick="upload()" th:utext="#{modal.save}"></button>

in the
attribute, the call for the function
should have one parameter, which value is stored in the thymeleaf variable

Anyone can tell mehow to use the expression in the above command?

I already try this:

  • th:onclick="upload(${gallery)"

  • th:attr="onclick=upload(${gallery)"

None of this worked.

Answer Source

I solve this issue with this approach:

th:onclick="|upload('${command['class'].simpleName}', '${gallery}')|"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download