Jazzy 1012
asked on
Make qty change inside array as well
I have this code:
<?php if($value1 != ''){?>
<div class="satin background_option">
<p style="display:inline-block;margin-right:150px"><?php echo @$value6[0]; ?></p>
<span style="float:right;">
<i id="qty-minus1" class="fa fa-minus-circle controls" style="color: #d7d6d0"></i>
<input id="qty1" type="number" value="0" min="0" step="1" style="border:1px solid #d7d6d0;background:transparent;width:35px;height:33px;color:#000;font-size:21px;font-weight:700;">
<i id="qty-plus1" class="fa fa-plus-circle controls" style="color: #d7d6d0"></i>
</span>
</div>
<?php }?>
It displays the amount along with add/minus qtys. var meal_qty = {};
var label_options = new Array();
var qty_options = new Array();
<?php foreach($label_name as $meal_option_id => $names_of_labels)
{?>
var meal_label_qty = <?php echo $meal_option_id; ?>;
meal_qty[meal_label_qty] = [];
var item = {
monday: '<?php echo $_SESSION['protiens']['mon'][$meal_option_id]['qty']?>' || '0',
tuesday: '<?php echo $_SESSION['protiens']['tues'][$meal_option_id]['qty']?>' || '0',
wedenday: '<?php echo $_SESSION['protiens']['wed'][$meal_option_id]['qty']?>' || '0',
thursday: '<?php echo $_SESSION['protiens']['thur'][$meal_option_id]['qty']?>' || '0',
friday: '<?php echo $_SESSION['protiens']['fri'][$meal_option_id]['qty']?>' || '0'
}
meal_qty[meal_label_qty] = item;
console.log(meal_qty);
<?php }?>
$('.option').on('click', function() {
$(".tab_options").hide();
var label = $(this).attr('label_option');
$("#qty1").val(meal_qty[label].monday);
$("#qty2").val(meal_qty[label].tuesday);
$("#qty3").val(meal_qty[label].wedenday);
$("#qty4").val(meal_qty[label].thursday);
$("#qty5").val(meal_qty[label].friday);
$("#label_option-" + label).show();
$('.option').removeClass("option-selected");
$(this).addClass("option-selected");
$('#protien_id').attr('value', label);
//alert(label); how to get protien
});
$("#qty-plus1").click(function() {
var val = parseInt($("#qty1").val(),10);
$("#qty1").val(val+1);
$("#add-to-cart").removeAttr('disabled').removeClass('view-disable').addClass('view-add');
$('#monday').attr('value',$("#qty1").val());
//$("#qty1").val();
});
$("#qty-minus1").click(function() {
var val = parseInt($("#qty1").val(),10);
if(val != 0) {
$("#qty1").val(val-1);
$('#monday').attr('value',$("#qty1").val());
$("#add-to-cart").removeAttr('disabled').removeClass('view-disable').addClass('view-add');
}
});
How can I make the qty-plus1 and qty-munis1 add and minus from the array as well, because if I go to another option they go and add one then go to a another then go back again it goes back to the old number, how can I solve this issue?ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.