Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf onclick send string as parameter value to javascript function

Tags:

thymeleaf

I want to pass multiple parameters on onClick in From Thymeleaf to javascript function.

<label th:onclick="getUserId(userId,email);" for="radio-11" data-toggle="tooltip" data-placement="bottom" data-trigger="hover"  class="pm-tab1-pad">

My Javascript function is:-

<script>
   function getUserId(userID,userEmail){
      console.log(userID,userEmail);
    }
</script>

How to do it?

like image 935
Nikant Chaudhary Avatar asked Apr 25 '26 02:04

Nikant Chaudhary


1 Answers

It can be done by using the following:-

<label th:onclick="getUserId([[${userId}]],[[${email}]] );" for="radio-11" data-toggle="tooltip" data-placement="bottom" data-trigger="hover"  class="pm-tab1-pad">

Here, userId is of Integer type end email is of String type.

Update :-

This also works:-

<label th:data-parameter1="${userId}" th:data-parameter2="${email}"  th:onclick="getUserId(this.getAttribute('data-parameter1'),this.getAttribute('data-parameter2'));" for="radio-11" data-toggle="tooltip" data-placement="bottom" data-trigger="hover"  class="pm-tab1-pad">
like image 86
Nikant Chaudhary Avatar answered Apr 30 '26 22:04

Nikant Chaudhary



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!