I have table with the price of quantity. I need count total sum if i write quantity in input and select the colors from dropdown and select product with the price. Firstly i need array of quantity and colors price. Second, check number is in table quantity column. Input must be smallest 30. For ex.: if number 299 - quantity is 200, if 4300 - quantity is 3000 and etc. to smaller. There is my table and jquery:
var total = $("#Total").val();
var table = Array();
$("table.quantity tr td:nth-child(1)").each(function (i, v) {
table[i] = $(this).text();
});
console.log(table);
$('#Quantity').on("input", function () {
var quantity = this.value;
var count = 0;
if (quantity >= 30) {
$.each(table, function (i, value) {
if (quantity >= parseInt(value)) {
count = value;
};
});
console.log(count);
}
});
$('#select-model').on('change', function(){
var price = $('option:selected', this).data('price');
if (total == '') {
total = 1;
}
$("#Total").val(price * total);
});
i think array must be like:
Array
(
[30] => Array
(
[1] => 1.4
[2] => 1.7
...
[8] =>
)
[50] => Array
(
[1] => 1.1
[2] => 1.3
...
[8] => 2.4
)
...
[5000] => Array
(
[1] => 0.3
[2] => 0.35
...
[8] => 1
)
)
there is my code: http://jsfiddle.net/Dewilas/cz69vL8u/
total result to be:
for ex.: 6.59 * 5000 * 0.3 (product1 * quantity 5000 * color 1)