Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
How to get HTML's thymeleaf value in javascript?

enter image description here

I send values using model.addAttribute in Spring, so I get values in HTML file well. and I want to get values in js files so I use document.getElementById but I can't get the value but 0 .. How to get html thymeleaf value in js? Thank you all..

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This you find this documented here: https://www.concretepage.com/thymeleaf/thymeleaf-javascript-inline-example-with-variable

The part which is interesting to you is the following:

<script th:inline="javascript">

/*<![CDATA[*/
  var user = /*[[${session.userName}]]*/ 'User Name';

/*]]>*/
</script>

In your case of course instead of session.userName you would put your variable name.

<script th:inline="javascript">

/*<![CDATA[*/
  var user = /*[[${modelVariable}]]*/ 'User Name';

/*]]>*/
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!