Jason28 Posted March 25, 2011 Share Posted March 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 26, 2011 Share Posted March 26, 2011 Try a javascript framework to make DOM manipulating easy. I don't think someone will write a function that you requested for free Quote Link to comment Share on other sites More sharing options...
sunfighter Posted March 26, 2011 Share Posted March 26, 2011 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> Quote Link to comment Share on other sites More sharing options...
Jason28 Posted March 26, 2011 Author Share Posted March 26, 2011 Thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.