How to get Current State of checkbox in thymeleaf th:onclick?

Viewed 126

I have a Checkbox and I call a function with th:onclick. This function takes the Value of checkbox After I Click it. But I don't Know How to Get the State of Checkbox Inside of th:onclick. the code looks like this:

<input type="checkbox" th:onclick="'javascript:userSettings(' + ${user.id} + ', this );'" th:checked="${user.enabled}" />

my function:

function userSettings(userId,userChk) { alert(userChk)}

After Clicking the Checkbox, the Value of "userChk" is undefiend.

How Can I Fix That?

1 Answers

My Fault, I forgot to get the Value of It:

function userSettings(userId,userChk) { alert(userChk.checked)}
Related