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

168
Vistas
Update a table cell with a randomly generated number

I am very new to javascript. I have only been working with it for a week. I have been trying to update the html table column with a 0 value to a random number generated by javascript. This is what I have tried so far, with the function "plays", but it produces no output. What errors do I have and what am I missing from my code? Any help would be greatly appreciated.

<table class="content-table">
<tbody id="groupH" onload="plays()">
<tr>
            <td>4</td>
              <td>Poland</td>
              <td>3</td>
              <td>1</td>
                <td id='updateDraw'>0</td>
                <td>2</td>
                <td>2</td>
                <td>5</td>
                <td>-3</td>
                <td>3</td>
              </tr>
          </tbody>
</table>

<!-- Update points table as page refreshes-->
    <script>
    function plays(){
document.getElementById("updateDraw").innerHTML = Math.floor(Math.random()* 10);
}
</script>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

There is no onload on a tbody element. This is raised when the window loads:

function plays() {
  document.getElementById("updateDraw").innerHTML = Math.floor(Math.random() * 10);
}

window.addEventListener("load", plays);
<table class="content-table">
  <tbody id="groupH">
    <tr>
      <td>4</td>
      <td>Poland</td>
      <td>3</td>
      <td>1</td>
      <td id='updateDraw'>0</td>
      <td>2</td>
      <td>2</td>
      <td>5</td>
      <td>-3</td>
      <td>3</td>
    </tr>
  </tbody>
</table>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can check it

<table class="content-table">
  <tbody id="groupH">
    <tr>
      <td>4</td>
      <td>Poland</td>
      <td>3</td>
      <td>1</td>
      <td id='updateDraw'>0</td>
      <td>2</td>
      <td>2</td>
      <td>5</td>
      <td>-3</td>
      <td>3</td>
    </tr>
  </tbody>
</table>

<!-- Update points table as page refreshes-->
<script>
  function plays(){
    document.getElementById("updateDraw").innerHTML =
    Math.floor(Math.random() * 10);
  }
  
  window.onload = function () {
    plays();
  }
</script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Another way is to attach the onload call to the <body> tag:

<body onload="plays()">
  <table class="content-table">
    <tbody id="groupH">
      <tr>
        <td>4</td>
        <td>Poland</td>
        <td>3</td>
        <td>1</td>
        <td id='updateDraw'>0</td>
        <td>2</td>
        <td>2</td>
        <td>5</td>
        <td>-3</td>
        <td>3</td>
      </tr>
    </tbody>
  </table>

  <!-- Update points table as page refreshes-->
  <script>
    function plays() {
      document.getElementById("updateDraw").innerHTML = Math.floor(Math.random() * 10);
    }
  </script>
</body>

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