I have researched code that does exactly what is required by my client. When choosing the number of boxes they are to send and submitting the result, the correct number of rows appears below. This is even better than I first wanted as the number of rows (boxes) can also be reduced if the wrong quantity is original submitted. This all works fine until..... This is to be added to within an existing form. When this code is submitted, the complete form is replaced by the rows ONLY, the existing form disappears. From investigating this problem, I get that you cannot put a form within a form. Can you please confirm this and if an alternative is possible, some help with the solution. Thanks in advance.
Boxes code
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<meta name="robots" content="noindex">
<title>Boxes</title>
<style id="boxes-css">
table>tr>td{width:60px;}
table>tr>td input{width:40px;}
#row1 {display: none; }
</style>
</head>
<body>
Number of boxes<br>
<input type="number" id="table-row-num" value="3">
<button id="submit">Submit</button>
<div id="table-gen">
<!--<p>Table generated here after clicking submit</p>-->
<table cellpadding="1" cellspacing="1" border="1">
<tr id="row1">
<td>Box 1</td>
<td><input type="name" placeholder="Material..."></td>
<td><input type="name" placeholder="Weight (kg)..."></td>
<td><input type="name" placeholder="Size (HxWxD)..."></td>
</tr>
</table>
</div>
<script>
$('button').on('click', generate);
function generate(e) {
var rows = $('#table-row-num').val();
var html = '';
for (var i = 0; i < rows; i++) {
html += '<tr>' +
'<td>' + (i + 1) + '</td>' +
'<td><input type="name" placeholder="Material"></td>' +
'<td><input type="name" placeholder="Weight (kg)..."></td>' +
'<td><input type="name" placeholder="Size (HxWxD)..."></td>' +
'</tr>';
}
$('table').html(html);
}
</script>
</body>
</html>