php代码使表循环可以连接

时间:2014-09-25 19:27:44

标签: javascript php html

当你点击" tambah sampel"我有一个循环的表。按钮。我需要提交的数据将它连接到有或没有循环的数据库,但不知道正确的PHP代码。我是编程的初学者,需要帮助。这是主表代码:

<INPUT type="button" value="Hapus Sampel" onclick="deleteRow('dataTable')" />

<TABLE id="dataTable" width="350px" border="1">
    <TR>
        <TD><INPUT type="checkbox" name="chk[]"/></TD>
        <td><input type="text" name="merk[]" size="12" maxlength="32" placeholder="Nama Merk"></td>
        <td><input type="date" name="tanggal_masuk[]" size="10" maxlength="32" placeholder="Tgl Masuk"></td>
        <td><input type="text" name="produsen[]" size="10" maxlength="32" placeholder="Produsen"></td>
        <td><input type="text" name="banyak_sampel[]" size="12" placeholder="Banyak Sampel"></td>
        <td><input type="text" name="jenis_sampel[]" size="11" placeholder="Jenis Sampel"></td>
        <td><input type="text" name="lot_no[]" size="5" maxlength="32" placeholder="No. Lot"></td>
        <td><input type="text" name="jumlah[]" size="5" maxlength="32" placeholder="Berat"></td>
         <td><input type="text" name="suhu_sampel[]" size="5" maxlength="32" placeholder="Suhu"></td>
        <td><select name="uji[]" size="1">
            <option value="Kosong">Jenis Uji</option>
            <option value="DNA Babi">DNA Babi</option>
            <option value="Etanol">Etanol</option>
            <option value="Porcine Detection Kit">Porcine Detection Kit</option>
            <option value="Daya Tembus Air">Daya Tembus Air</option>
            <option value="Formalin">Formalin</option>
            <option value="Identifikasi Kulit dan Bulu">Identifikasi Kulit/Bulu</option>
            </select> 
         </td>
        <td><select name="status[]" size="1" >
        <option value="Kosong">Jenis Pengujian</option>
        <option value="Accelerated">Accelerated</option>
        <option value="Normal">Normal</option>
        </select></td>
        <td><select name="kondisi_sampel[]" size="1">
            <option value="Kosong">Kondisi</option>
            <option value="Baik">Baik</option>
            <option value="Busuk">Busuk</option>
            <option value="Rusak">Rusak</option>
            </select></td>
        <td><select name="jenis_kemasan[]" size="1">
            <option value="Kosong">Kemasan</option>
            <option value="PlastikSeal">Plastik Seal</option>
            <option value="BotolBening">Botol Bening</option>
            <option value="KemasanAsli">Kemasan Asli</option>
            </select>
        </td>
    </TR>
</TABLE>
    <tr>
        <td><input type="submit" name="submit" value="Simpan"></td>
    </tr>
</table>

和js:

   function addRow(tableID) {

        var table = document.getElementById(tableID);

        var rowCount = table.rows.length;
        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;
            //alert(newcell.childNodes);
            switch(newcell.childNodes[0].type) {
                case "text":
                        newcell.childNodes[0].value = "";
                        break;
                case "checkbox":
                        newcell.childNodes[0].checked = false;
                        break;
                case "select-one":
                        newcell.childNodes[0].selectedIndex = 0;
                        break;
            }
        }
    }

    function deleteRow(tableID) {
        try {
        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 delete all the rows.");
                    break;
                }
                table.deleteRow(i);
                rowCount--;
                i--;
            }


        }
        }catch(e) {
            alert(e);
        }
    }

0 个答案:

没有答案