Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda