Kleber Mota Kleber Mota - 9 months ago 216
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.


I solve this issue with this approach:

th:onclick="|upload('${command['class'].simpleName}', '${gallery}')|"