I have a form with the following text fields that I would want to push as an array:
<input type="text" name="qty" placeholder="regular-price" class="ticket-quantity" id="tickets" value="1">
<input type="text" name="qty" placeholder="vip-price" class="ticket-quantity" id="tickets" value="1">
<input type="text" name="qty" placeholder="viip-price" class="ticket-quantity" id="tickets" value="1">
Am using this function but not getting the desired output:
var tickets = [];
$.each($("input#tickets"), function(){
var quantity = $(this).parent().find('input.ticket-quantity').val();
tickets.push({"tickets" : $(this).val(), "value" : quantity});
});
ajax_data.tickets = tickets;
How do I write my Javascript to pull:
tickets[0][ticket] "regular-ticket"
tickets[0][value] "2"
tickets[1][ticket] "vip-ticket"
tickets[1][value] "1"
tickets[2][ticket] "viip-ticket"
tickets[2][value] "0"