خرید بک لینک
In a form I have two tables, each with a single row initially, 4 cells in each, 4 inputs, button, text, number, number. Button on row 0 adds a row, buttons on subsequent rows deletes the row. The tables are identical except the input names are all different. Taking one table like this
Code:

<table id="Table1" style="width: 100%;">
                                                <tr>
                                                <td style="width: 5%;"></td><td style="height: 40px; width: 65%; text-align: center; font-size: 20px;">Col2</td><td style="width: 15%; font-size: 20px; text-align: center;">Col3</td><td style="width: 15%; font-size: 20px;">Col4</td>
                                                </tr>
                                                <tr>
                                                        <td ><input type="button" value="+" onclick="addRow(this);"></td>
                                                        <td style="height: 40px; font-size: 20px;"><input type="text" name="Col2" style="height: 40px; width: 100%; font-size: 20px;" required></td>
                                                        <td style="height: 40px; width: 15%;"><input type="number" name="Col3" min="0" value="0" step="1" style="height: 40px; width: 100%; font-size: 20px;" required></td>
                                                        <td style="height: 40px; width: 15%;"><input type="number" name="Col4" min="0" max="11" value="0" step="1" style="height: 40px; width: 100%; font-size: 20px;" required></td>
                                                </tr>
                                        </table>

This is the JS to add a row
Code:

function addskill()
{
var table = document.getElementById("Table1");
var rows = document.getElementById("Col2").getElementsByTagName("tr").length;
var insertrow = table.insertRow(rows);
var cell1 = insertrow.insertCell(0);
var cell2 = insertrow.insertCell(1);
var cell3 = insertrow.insertCell(2);
var cell4 = insertrow.insertCell(3);
var element0 = document.createElement("input");
element0.type="button";
element0.value="-";
element0.onclick = function(){deleteRow(this);};
cell1.appendChild(element0);
var element1 = document.createElement("input");
element1.type = "text";
element1.name = "Col2";
element1.style = "height: 40px; width: 100%; font-size: 20px;"
cell2.appendChild(element1);
var element2 = document.createElement("input");
element2.type = "number";
element2.name = "Col3";
element2.min  = "0";
element2.value = "0";
element2.step = "1";
element2.style = "width: 100%; height: 40px; font-size: 20px;";
cell3.appendChild(element2);
var element3 = document.createElement("input");
element3.type = "number";
element3.name="Col4";
element3.min  = "0";
element3.value = "0";
element3.max = "11";
element3.step = "1";
element3.style = "width: 100%; height: 40px; font-size: 20px;";
cell4.appendChild(element3);
}

function deleteRow(x)
{
var table = document.getElementById("Table1");
var index = x.closest('tr').rowIndex;
table.deleteRow(index);
}

The problem is if I submit with 2 rows in each table, only one row is showing in mysql. Troubleshooting, POST count for each of the inputs is 1. No idea why. If 2 inputs in the same column have the same name, count in POST should be 2, shouldn't it?

برچسب: نویسنده: آیلین رضوانی تاريخ: سه شنبه 26 دی 1396 ساعت: 9:14

صفحه بندی