submit a row data in dynamic table
NickName:Terry Ask DateTime:2016-10-08T04:21:46

submit a row data in dynamic table

I made a dynamic table with checkbox. I only want to submit the data in checked row to the form. I try to use checkbox array index but that does not work. What should I do to only submit the data in a checked row?

function addRow(tableID) {
  var table = document.getElementById(tableID);
  var rowCount = table.rows.length;
  if (rowCount < 5) {
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    for (var i = 0; i < colCount; i++) {
      var newcell = row.insertCell(i);
      newcell.innerHTML = table.rows[0].cells[i].innerHTML;
    }
  } else {
    alert("Maximum number of extra data is 5.");
  }
}


function deleteRow(tableID) {
  var table = document.getElementById(tableID);
  var rowCount = table.rows.length;
  for (var i = 0; i < rowCount; i++) {
    var row = table.rows[i];
    var chkbox = row.cells[0].childNodes[0];
    if (null != chkbox && true == chkbox.checked) {
      if (rowCount <= 1) {
        alert("Cannot remove all.");
        break;
      }
      table.deleteRow(i);
      rowCount--;
      i--;
    }
  }
}
<p>
  <input type="button" value="Add Option" onClick="addRow('dataTable')" />
  <input type="button" value="Remove Option" onClick="deleteRow('dataTable')" />
  <table id="dataTable">
    <tbody>
      <tr>
        <p>
          <td>
            <input type="checkbox" required="required" name="chk[]" checked="checked" />
          </td>
          <td>
            <label>Name of Data:</label>
            <input type="text" name="dataName">
          </td>
          <td>
            <label>Data:</label>
            <input type="text" name="data">
          </td>
        </p>
      </tr>
    </tbody>
  </table>

Copyright Notice:Content Author:「Terry」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39925225/submit-a-row-data-in-dynamic-table

More about “submit a row data in dynamic table” related questions

submit a row data in dynamic table

I made a dynamic table with checkbox. I only want to submit the data in checked row to the form. I try to use checkbox array index but that does not work. What should I do to only submit the data i...

Show Detail

Enable/Disable submit button if dynamically table has no row

I have form with few fields and a dynamic table (ID- installments with "Add new Row" button. Entire form has submit button. I want to disable the submit button if the dynamic table has no row. And,...

Show Detail

Dynamic table on click of row submit the hidden value within the tr only

I have a dynamic table using php and html which can be clicked and on click the table which is in a form submits and using the post method it post the two variables that are of the particular row. ...

Show Detail

How can I submit the data from dynamic table into database?

Currently I have a dynamic table inside the form using the following HTML and Javascript code: &lt;script type="text/javascript"&gt; function addRows(){ var table = document.getElement

Show Detail

Displaying data on row of submit button

Basically I have a table that is being used to display data from an sql table. Each row in the database is looped through so each row in the database is also displayed on a new row in the html tab...

Show Detail

submiting data from a dynamic table to database - PHP

I have a html webpage which has a table that gets data from a table in my database. Each row has a button that when clicked gets added into another table on the webpage dynamically using javascript...

Show Detail

Hide Table Row After Submit

I have a table with rows of data from a mysql query. Each row has a radio button and a submit button. My goal is to hide the table row after the submit button has been clicked. echo '&lt;tbody&g...

Show Detail

Submit dynamic table inputs

I want to store a table data in my website. The table has n row and every row has m column (It is a dynamic table). Every cell has an input. So we have n * m inputs. How can I store data in JSON f...

Show Detail

How to create and submit Dynamic table which has rowspan - JQuery

I have a webpage where a user can create a dynamic table, user can also add groups, and add genre in the group and add movies according to the genre. An example of my data is below: my data Curre...

Show Detail

Display the data in the append table row then Submit or Insert to Database

Good Day! I'm just thinking and researching how can I execute the given problem to me. My program has a ADD button then it will pop-up the Modal Form that you will input data then when you insert it

Show Detail