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

203
Vistas
Pass HTML Table Row Value to Javascript function on load
<html>
    <td id="test" onload="GetValue('{{name}}')"></td>
</html>
<script>
    function GetValue(value){
        value+="Hello";
        document.getElementById("test").innerText=value;
    }
</script>

The goal is to have table row as "JohnHello" directly on page load. I am using Handlebars and let's suppose "John" has been passed on the {{name}} variable.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The load event is fired for the window... And some other elements like <img>... But not on a <td>.

In the below snippet, I used the onload attribute on the <body>. That is because it directly belongs to window. You can target it using window.document.body.

Additionnaly, I would suggest you to test using valid HTML. So to have a <td> inside a <tr> and a <table>... And the <script> tag inside the <body>.

That will spare you time for sure.

<html>

<body onload="GetValue('john')">
  <table>
    <tr>
      <td id="test"></td>
    </tr>
  </table>


  <script>
    function GetValue(value) {
      value += "Hello";
      document.getElementById("test").innerText = value;
    }
    
    // This log is to show that <body> directly belongs to window
    console.log(window.document.body)
  </script>
</body>

</html>

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