Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda