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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.