I have this code:
<?php
if(mysqli_num_rows($result2) >= 2){
foreach($label_name as $meal_option_id => $names_of_labels)
{
echo '<button price='.$protein_prices[$meal_option_id].' label_option= '.$meal_option_id.' data-label-option= '.$meal_option_id.' class="view1 white cbtn1 open_sansbold option protein-option">' .$names_of_labels. ' <span id="price-difference-for-'.$meal_option_id.'"></span></button>';
}}?>
Javascript:
$(function() {
var meal_qty = new Array();
var label_options = new Array();
var qty_options = new Array();
$(".protein-option").click(function() {
var meal_label_qty = $(this).data("label-option");
// CREATE THE ASSOCIATIVE LABEL
meal_qty[meal_label_qty] = [];
// CREATE THE OBJECT WITH VALUES
var item = {
mon: $("#qty1").val(),
tues: $("#qty2").val(),
wed: $("#qty3").val(),
thur: $("#qty4").val(),
fri: $("#qty5").val()
}
// ADD TO ARRAY
meal_qty[meal_label_qty] = item;
console.log(meal_qty);
});
});
Now item does contain the right values and so does meal_label_qty but my console log is:
(1003) [undefined × 1002, Object]
I wanted this output:
[meal_label_qty]
{
mon: $("#qty1").val(),
tues: $("#qty2").val(),
wed: $("#qty3").val(),
thur: $("#qty4").val(),
fri: $("#qty5").val() //WHICH IS ITEM
}
I realized my code goes the right meal_label_qty and item but starts writing Object after this code line meal_qty[meal_label_qty] = [];