How to count total sum jquery? -


i have table price of quantity. need count total sum if write quantity in input , select colors dropdown , select product price. firstly need array of quantity , colors price. second, check number in table quantity column. input must smallest 30. ex.: if number 299 - quantity 200, if 4300 - quantity 3000 , etc. smaller. there table , 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 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 code: http://jsfiddle.net/dewilas/cz69vl8u/

total result be:

for ex.: 6.59 * 5000 * 0.3 (product1 * quantity 5000 * color 1)

i think, want multiplication , not sum -

see if following helps -

you can add common class selector of inputs , calculation. have assumed 'myinput'.

$('.myinput').on('change', function () {          var total = 1;         var input_val;          $('.myinput').each(function(){              if($(this).attr("id") == "select-model"){                 input_val = $('option:selected', this).data('price');             }             else{                 input_val =  $(this).val();             }              if (input_val == '' || input_val == 0) {                 input_val = 1;             }             total = total * input_val;          });          $("#total").val(total);     }); 

note: have considered quantity 1 default value other inputs can seen default in total box, can change if want.

js fiddle: http://jsfiddle.net/cz69vl8u/22/


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -