Jump to content

Add new html table row and textfield?


Jason28

Recommended Posts

Hello, could anyone please provide me with a function where I can add a number like 4 for example, and when the option to select 4 is selected from a dropdown form, it will insert 4 rows of whatever html I want to add into the page? So if they select 2, two rows are created and 4, 4 rows are created.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/231662-add-new-html-table-row-and-textfield/
Share on other sites

Not too hard. You should be able to expand this for your needs. This writes a three cell up to 4 row table.

 

HTML

<body>

<select>
<option onclick="make_table(1);">1 Row</option>
<option onclick="make_table(2);">2 Row</option>
<option onclick="make_table(3);">3 Row</option>
<option onclick="make_table(4);">4 Row</option>
</select>
<div id="here"></div>

</body>

 

The javascript

<script type="text/javascript">
function make_table(amount){

var row = '';
for (i=1;i<=amount;i++)
{
row += "<tr><td>Empty</td><td>Empty</td><td>Empty</td></tr>"
}


document.getElementById('here').innerHTML = ("<table width=\"400\" border=\"1\">"
+"<caption>Auto Table</caption>"
+row
+"</table>");
}
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.