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