Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf onclick send td value to javascript function

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.

like image 507
Gururaj Mb Avatar asked Jun 23 '26 13:06

Gururaj Mb


2 Answers

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);
}                           
like image 198
Gururaj Mb Avatar answered Jun 26 '26 02:06

Gururaj Mb


For passing multiple parameters, you can use the following:

th:onclick="'doSomething(\''+${val1}+ '\',\''+${val2}+'\',\''+${val3}+'\');'"
like image 35
Prabhat Avatar answered Jun 26 '26 02:06

Prabhat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!