2

I tried the following syntax but it didn't work for me. Please let me know the answer.

Javascript Code --->

function passValue(id, name){
        
        console.log(id)
        console.log(name)
    document.getElementById("updateId").value=id; 
        }

Thymeleaf code -->

<input type="button" th:onclick="passValue(\''+${data.id}+'\', \''+${data.newEntryName} +'\')" value="Update" />

It shows an error like:

SyntaxError: Unexpected Token.

2
  • Welcome to stackoverflow! Did you check the resulting HTML in your browser? How does it look like? Is there any exception in the logs? Commented Jan 25, 2022 at 7:31
  • Thank you, Wim; Yes, there it shows an error like; SyntaxError: Unexpected Token. Commented Jan 25, 2022 at 7:35

1 Answer 1

1

I recommend you do JavaScript arguments like this (notice I'm using onclick and not th:onclick):

<input  type="button"
        th:data-id="${data.id}"
        th:data-name="${data.newEntryName}"
        onclick="passValue(this.getAttribute('data-id'), this.getAttribute('data-name'));"
        value="Update" />
Sign up to request clarification or add additional context in comments.

Comments

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.