consider code below:

//Consider the php part(process.php)

<table border="1">
    <?php foreach($_POST['names'] as $k=>$v){ ?>
        <td><?php echo $v; ?></td>
        <td><?php echo $_POST['languages'][$k]; ?></td>
    <?php } ?>

//html part``

    <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
    <script language="javascript">
function name_loop(){
    var names_array = [];
        names_array[index] = $.trim($(this).val());
    return names_array;
        function addRow(tableID) {

            var table = document.getElementById(tableID);

            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);

            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";

            var cell2 = row.insertCell(1);
            cell2.innerHTML = rowCount + 1;

            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";


        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) {

            }catch(e) {

 <!--<form action="process.php" method="post">-->
    <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />

    <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />

    <TABLE id="dataTable" width="350px" border="1">
            <TD><INPUT type="checkbox" name="chk"/></TD>
            <TD> 1 </TD>
            <TD> <INPUT type="text" class="name_class" name="txt" /> </TD>
<input type="submit" name="btn_submit" id="btn_submit" value="check"  onclick="send_off();"/>
<div id="result"></div>
<script type="text/javascript">
function send_off(){
    var names = name_loop(); //stores the array of names
    //var languages = lang_loop();  //stores the array of languages

    $('#result').load('process.php', {'names' : names}); //submit to php script
    $('input[type=text]').val(''); //empty all textbox

the problem is thea it only prints one row i.e does not loop through the array printing each element. what is the problem ?

why in the PHP section?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.