2

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?

2
  • have you checked your label is clicked without passing any parameters? try doing in this way <ELEMENT onclick="handler"> Commented Jul 8, 2019 at 12:56
  • Yes, i have checked. Commented Jul 8, 2019 at 12:59

1 Answer 1

9

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">
Sign up to request clarification or add additional context in comments.

2 Comments

This will not work going forward. Look at this stackoverflow.com/questions/54224058/…
I have updated the answer, but you downvoted my earlier answer,was my answer wrong ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.