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

157
Vistas
How can add checkbox in input from enter?

How can add checkbox in input from enter?

<html>
        <head>
    
        </head>
        <body>
     Search: <input onkeyup="myFunction()" type="search" id="mySearch" value="">
    <p>Click the button to display the value of the value attribute of the search field.</p>
    <p id="demo"></p> 
     <table id="table">
       <tr>
       <td></td>
       </tr>
     </table>
     <script>
        function myFunction()
    {
      if(event.keyCode === 13){
        debugger;
        var table = document.getElementById("table");
        var row   = table.insertRow(-1);
        var date  = row.insertCell(0);
        table.appendChild(row); 
        date.innerHTML  = document.getElementById("mySearch").value;
      
        //insert checkbox//
        function editTd()
        {
        var rows = document.getElementById('table').rows;
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
          for(var j =0; j<row.cells.length; j++){
            var inputs = document.createElement("input");
            inputs.type = "checkbox";
          rows.cells[j].appendChild(inputs);
          };
        };
        };      
        editTd();
      
      }
     
    }
     </script>
        </body>
    </html>

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

you just need to alter the line to this:

rows[i].cells[j].appendChild(inputs);

or possibly

rows[0].cells[j].appendChild(inputs);

<html>

<head>

</head>

<body>
  Search: <input onkeyup="myFunction()" type="search" id="mySearch" value="">
  <p>Click the button to display the value of the value attribute of the search field.</p>
  <p id="demo"></p>
  <table id="table">
    <tr>
      <td></td>
    </tr>
  </table>
  <script>
    function myFunction() {
      if (event.keyCode === 13) {
        debugger;
        var table = document.getElementById("table");
        var row = table.insertRow(-1);
        var date = row.insertCell(0);
        table.appendChild(row);
        date.innerHTML = document.getElementById("mySearch").value;

        //insert checkbox//
        function editTd() {
          var rows = document.getElementById('table').rows;
          for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            for (var j = 0; j < row.cells.length; j++) {
              var inputs = document.createElement("input");
              inputs.type = "checkbox";
              rows[i].cells[j].appendChild(inputs);
            };
          };
        };
        editTd();

      }

    }
  </script>
</body>

</html>

it shows 2 checkbox's so if that is not what you wanted just need to change your loop logic. I hope this helps

about 4 years ago · Santiago Gelvez 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