Calculators.js

De Wiki The-West ES
Ir a la navegación.

ui = {

   initPage: function () {
       console.log("Calculators Script loaded");
       
       //Calculator       
       var newInput = "<input type='number' class='input_amount target' value='1' max='50000' min= />";
       ($('#input_amount')).html(newInput);
       var amountsArray = [];
       $('.item_number').each(function(index, element){
           console.log(parseInt($(element).text()));
           amountsArray[index] = parseInt($(element).text());
       })
       $(".input_amount").on('change', function() {
           if(isNaN($(".amount_input") && $(".amount_input").value > 0)){
               var inputValue = $('.amount_input').value;
               $('.item_number').each(function(index, element){

console.log(amountsArray[index] * inputValue);

                   $(element).text(amountsArray[index] * inputValue);
               })
           }else{
               $('.item_number').each(function(index, element){

console.log(amountsArray[index] * inputValue);

                   $(element).text(amountsArray[index]);
               })
           }
       });
       
   },
   
 init: function () {
       ui.initPage();
   }

}

ui.init();