I currently have a system which allows users to add different ticket types. I want each ticket property to have a unique name so that when the form is submitted I can tell the tickets apart.
Right now, there is a button to add more tickets to the page if the user needs more than one.
I have tried to get it to append the ticket number to the html name attribute but it's not working. It is successfully creating more ticket divs but its using the same name attribute.
Can anyone help with this?
HTML
<div id="tickets">
<div id="ticket" class="form-inline margin-bottom-40">
<label class="control-label col-md-3">
Ticket
<span class="required"> * </span>
</label>
<div class="col-md-8">
<input type="text" class="form-control" placeholder="Name" name="ticketname" />
<input type="text" class="form-control" placeholder="Price" name="ticketprice" />
<input type="text" class="form-control" placeholder="Max Quantity" name="ticketmax" />
<a onclick="moreTickets()">
<i class="fa fa-plus"></i>
</a>
</div>
<br>
<br>
</div>
</div>
More tickets javascript
var counter = 0;
function moreTickets() {
counter++;
var newFields = document.getElementById('ticket').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i = 0; i < newField.length; i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
}
var insertHere = document.getElementById('tickets');
insertHere.parentNode.insertBefore(newFields, insertHere);
}
