Navin Nandakumar Navin Nandakumar - 6 months ago 9
HTML Question

Need to copy cell value to another cells in the html table

i am using the simple html code where i want to copy the 1st cell value to all other cells.
this how html table looks
and also trying to autofill the remaining dates when i give the input in 1st cell

added my code below

Answer

Assuming you want this, so i hope this is helpful

function bindData(target) {
  var inputs = document.querySelectorAll(target);

  if (inputs) {
    for (var k = 0; k < inputs.length; k++) {
      inputs[k].addEventListener('keyup', function() {
        var fields = document.querySelectorAll(this.dataset.bind);
        var value = this.value;
        if (fields) {
          for (var i = 0; i < fields.length; i++) {
            fields[i].value = value;
          }
        }

      });
    }
  }

}

bindData('[data-bind]');
<table>
  <tr>
    <td>
      <input data-bind=".date" type="text">
    </td>
    <td>
      <input class="date" type="text">
    </td>
    <td>
      <input class="date" type="text">
    </td>
  </tr>
  <tr>
    <td>
      <input data-bind=".name" type="text">
    </td>
    <td>
      <input class="name" type="text">
    </td>
    <td>
      <input class="name" type="text">
    </td>
  </tr>
</table>