I have tried several ways to get this to work, but never seem to have any success. I want the innerHTML from the below javascript to display x amount of times, based on the value selected in the dropdown box, then to submit all fields to another php which will insert into mysql. When I have tried cloning the section of HTML, it only posts the values in the last clone to the next form. I would like all values from all "cloned" portions to be sent through. Any help would be greatly appreciated!
I have the following HTML:
<form action="?page=book_add" method="post" name="add_booking" id="book" target="_self" enctype="multipart/form-data">
<center><table><tr><td class="form_label">Passengers</td><td valign="middle">
<select id="numpass" name="numpass" class="form_e"/>
<option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td></tr></table></center>
<div id="repeat"></div>
<table width="100%"><tr><td></td><td style="text-align:right"><input type="submit" value="Add Booking" /></td></tr>
</table>
</form>
Javascript:
$(function(){
$("#numpass").change(addInput);
});
var counter = parseInt($("#numpass").val());
var limit = 7;
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "<div class='form_head'>Passenger " + counter + " - Details</div>
<br />
<table width='100%' cellpadding='2' cellspacing='4'>
<tr>
<td class='form_label'>First Name: <input type='text' name='cust_fname[]' class='form_f' required='required'/> Last Name: <input type='text' name='cust_lname[]' class='form_f' required='required'/> Weight (kg): <input type='text' name='cust_kg[]' class='form_a' required='required'/></td>
</tr>
<tr>
<td class='form_label'>Phone: <input type='text' name='cust_phone[]' class='form_g' required='required'/> Email: <input type='text' name='cust_email[]' class='form_d' /></td>
</tr>
<tr>
<td>
<table width='100%' cellpadding='2' cellspacing='4'>
<tr><td class='form_label'>Address:</td></tr>
<tr>
<td class='form_label'>Number: <input type='text' name='cust_addr_num[]' class='form_a' /> Street: <input type='text' name='cust_addr_street[]' class='form_b' /> Suburb/Town: <input type='text' name='cust_addr_sub[]' class='form_f' /></td></tr>
<tr><td class='form_label'>State: <input type='text' name='cust_addr_state[]' class='form_b' /> Postcode: <input type='text' name='cust_addr_post[]' class='form_a' /> Country: <select class='form_c' name='cust_addr_country[]'>
<option value=''>--- Select Country ---</option>
<option value='Australia'>Australia</option></select></td></tr></table>
</td></tr></table>
<br />";
$(newdiv).appendTo("#repeat");
/*document.getElementById(divName).appendChild(newdiv);
counter++;*/
}
}