Thymeleaf onclick send td value to javascript function

14,966

Solution 1

Above issue is resolved now, we need to use Thymeleaf specific syntax.

th:onclick="'getPropId(\'' + ${properties.id} + '\');'"

Now if its displying proper properties.id in javascript function.

function getPropId(inputID){
    alert(inputID);
}                           

Solution 2

For passing multiple parameters, you can use the following:

th:onclick="'doSomething(\''+${val1}+ '\',\''+${val2}+'\',\''+${val3}+'\');'"

Solution 3

Cleaner with literal substitution ||:

th:onclick="|getPropId('${properties.id}');|"

Multiple case:

th:onclick="|getPropId('${var1}','${var2}');|"
Share:
14,966
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I am using "Thymeleaf", I want to send the value to javascript, I am new to this, I am trying below code:

    onclick="getPropId('${properties.id}')"
    

    and function

    getPropId(inputID){alert(inputId);}
    

    But I am not getting actual value.

  • rajadilipkolli
    rajadilipkolli almost 8 years
    How to achieve if I have two parameters to be passed