Add table row in JavaScript
Code example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<html> <head> <script type="text/javascript"> function displayResult() { document.getElementById("myTable").insertRow(-1).innerHTML = '<td>txt</td><td><input type="text" name="txt[]" placeholder="txt" required></td>'; } </script> </head> <body> <form method="post" action="https://devbanban.com/"> <p align="center"><button type="button" onclick="displayResult()">Insert new row</button> </p> <table id="myTable" border="1" width="400px" align="center"> <tr> <td>txt</td> <td><input type="text" name="txt[]" placeholder="txt" required></td> </tr> <tr> <td>txt</td> <td><input type="text" name="txt[]" placeholder="txt" required></td> </tr> </table> <p align="center"> <button type="submit">Save</button> </p> </form> <br /> </body> </html> |
output
ref : https://stackoverflow.com/questions/171027/add-table-row-in-jquery