Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!