Diferencia entre revisiones de «Calculators.js»

De Wiki The-West ES
Ir a la navegación.
Sin resumen de edición
Sin resumen de edición
Línea 9: Línea 9:
         var amountsArray = [];
         var amountsArray = [];
         $('.item_number').each(function(index, element){
         $('.item_number').each(function(index, element){
            console.log(parseInt($(element).text()));
             amountsArray[index] = parseInt($(element).text());
             amountsArray[index] = parseInt($(element).text());
            console.log(amountsArray[index]);
         })
         })
         $(".input_amount").on('change', function() {
         $(".input_amount").on('change', function() {
Línea 16: Línea 16:
                 var inputValue = $('.amount_input').value;
                 var inputValue = $('.amount_input').value;
                 $('.item_number').each(function(index, element){
                 $('.item_number').each(function(index, element){
console.log(amountsArray[index] * inputValue);
                  console.log(amountsArray[index]);
                  console.log(inputValue);
                  console.log(amountsArray[index] * inputValue);
                     $(element).text(amountsArray[index] * inputValue);
                     $(element).text(amountsArray[index] * inputValue);
                 })
                 })
             }else{
             }else{
                 $('.item_number').each(function(index, element){
                 $('.item_number').each(function(index, element){
console.log(amountsArray[index] * inputValue);
                  console.log(amountsArray[index]);
                  console.log(inputValue);
                  console.log(amountsArray[index] * inputValue);
                     $(element).text(amountsArray[index]);
                     $(element).text(amountsArray[index]);
                 })
                 })

Revisión del 02:36 29 ago 2023

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){
           amountsArray[index] = parseInt($(element).text());
           console.log(amountsArray[index]);
       })
       $(".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]);
                 console.log(inputValue);
                 console.log(amountsArray[index] * inputValue);
                   $(element).text(amountsArray[index] * inputValue);
               })
           }else{
               $('.item_number').each(function(index, element){
                 console.log(amountsArray[index]);
                 console.log(inputValue);
                 console.log(amountsArray[index] * inputValue);
                   $(element).text(amountsArray[index]);
               })
           }
       });
       
   },
   
 init: function () {
       ui.initPage();
   }

}

ui.init();