Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i Have a table which is already have textbox and button. i want when user click (Add) button then automatically add new row with same textbox and same button with add action.

Below is my code.


please help me how to i add new row, and my (
Product_name
)textbox is auto complete feature.

please Help

What I have tried:

<pre><table id="product_table" class="display" cellspacing="0" width="50%">
        <thead>
            <tr>
                <th align="Center">Product Name</th>
                <th align="Center">Quantity</th>
                <th align="Center">Click Me</th>
            </tr>
        </thead>		
         <tbody>
            <tr>
                <td><input class="product_text" type="text" placeholder="Type Product Name" name="Product_name" id="Product_name" required="">
                </td>
                <span id="product_list"></span> 
                <td><input class="product_text" type="text" placeholder="Quantity" name="Quantity" required=""></td>
                <td><input class="product_text" type="button" id="addRow" name="addRow" value="Add"></td>
            </tr>
            </tbody>
            </table>

$("#addRow").click(function(){
      table.row.add( [
      ] ).draw( false );
  });
Posted
Updated 26-Jul-17 0:06am

1 solution

Here I have used Simple Javascript instead of Jquery


<input class="product_text" onClick="AddNewRow()" type="button" id="addRow" name="addRow" value="Add">


JavaScript
function AddNewRow()
{
  var table = document.getElementById("product_table");
  var row = table.insertRow(table.rows.length);
  var cell1 = row.insertCell(0);
  var cell2 = row.insertCell(1);
  var cell3 = row.insertCell(2);

  cell1.innerHTML = "<input type='text' class='product_text' placeholder ='Type product Name' />"
  cell2.innerHTML = "<input type='text' class='product_text'  placeholder ='Quantity' />"
  cell3.innerHTML = "<input class='product_text' type='button' onClick='AddNewRow()' name='addRow' value='Add'>"
}
 
Share this answer
 
v2
Comments
Member 10484162 26-Jul-17 15:33pm    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900