When inserting number in input, update the other two without having to change input

0

As I said in the question, I am updating some inputs through what I insert in two of them, the quantity and the unit price. Now I am updating well with AJAX, but you need to change the input to actialize, is there any way to write if you update instantly ??? Greetings

The AJAX

      $('#ePrecioUnd, #cntComprada').on("change", function(e) {
         var unidad = $(this).val();
          var precio = $("#ePrecioUnd").val();
          var cantidad = $("#cntComprada").val();

           var datos = {
            'precio': precio,
            'cantidad': cantidad,
             };
               $.ajax({
                  url: "sumasFact.php",
                  type: "post",
                  dataType: "json",
                  data: datos,
                  success: function (resultado){
                    $("#eSubTotal").val(resultado.totalConCantidades);
                    $("#iva").val(resultado.ivaD100);
                    $("#eTotal").val(resultado.ivaTotal);
                  }
              });
         console.log(unidad);
        });

The Answer

include ("../conexion/conexion.php");


$cantidad =$_POST['cantidad'];
$precio=$_POST['precio'];
$totalConCantidades = $precio * $cantidad;
$ivaX21 = $totalConCantidades*21;
$ivaD100 = $ivaX21/100;
$ivaTotal = $ivaD100 + $totalConCantidades;

$resultado=array();
  $resultado['totalConCantidades'] =  $totalConCantidades;
  $resultado['ivaD100'] =  $ivaD100;
  $resultado['ivaTotal'] =  $ivaTotal;
echo json_encode($resultado)

And I enter it in the input with the #ID

    
asked by Miguel 27.10.2018 в 18:30
source

1 answer

1

Solution with the help of @ lois6b

// Evento que es lanzado cuando se escribe en un campo. busca así: event when type jquery. =)
      $('.inputcalculo').keyup(function(e) {
         var unidad = $(this).val();
          var precio = $("#ePrecioUnd").val();
          var cantidad = $("#cntComprada").val();
          console.log(precio + " - " + cantidad);
           var datos = {
            'precio': precio,
            'cantidad': cantidad,
             };
               $.ajax({
                  url: "sumasFact.php",
                  type: "post",
                  dataType: "json",
                  data: datos,
                  success: function (resultado){
                    $("#eSubTotal").val(resultado.totalConCantidades);
                    $("#iva").val(resultado.ivaD100);
                    $("#eTotal").val(resultado.ivaTotal);
                  }
              });
         //console.log(unidad);
        });

Simply add event keyup

    
answered by 05.11.2018 / 11:48
source