I have this jquery code in which I assign the values obtained in txtVlr and txtQuantity to some variables, then multilink them and the result put it in the txtSubtotal just when there is a change in the txtquantity, but when executing it the variables do not obtain the value and finally there is no result. The value of txtVlr is obtained by selecting an id in the txtidarticle (I do not know if it has anything to do). the value of txt Quantity is entered by the user.
<head>
<script>
$(document).ready(function(){
var $Valor = $("#txtVlr").val();
var $Cantidad = $("#txtCantidad").val();
$("#txtCantidad").change(function(){
$Subtotal = parseInt($Valor)*parseInt($Cantidad);
alert ($Valor);
alert ($Cantidad);
$("#txtSubtotal").val($Subtotal);
alert ($Subtotal);
});
});
</script>
</head>
<body>
<form>
<div class="Container">
<div class="margen">
<div class="col-xs-2">
<label for="ex1">ID del Articulo</label>
<!-- DEBE TENER UN DDL PARA LA BASE DE DATOS-->
<?php
$CON = mysqli_connect("localhost","root","","BDfactura") or die ("error");
$query="Select * From Articulo";
$sql = mysqli_query($CON, $query);
?>
<input class="form-control" id="txtidArticulo" type="text" list="Articulos">
<datalist id="Articulos">
<?php
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['IdArticulo']; ?>"></option><?php } ?>
</datalist>
<?php mysqli_close($CON); ?>
</div>
<div class="col-xs-2">
<label for="ex1">Descripcion</label>
<!-- DEBE TENER UN DDL PARA LA BASE DE DATOS-->
<input class="form-control" id="txtDescripcion" type="text">
</div>
<div class="col-xs-2">
<label for="ex1">Valor Venta</label>
<!-- DEBE TENER UN DDL PARA LA BASE DE DATOS-->
<input class="form-control" id="txtVlr" type="text">
</div>
<div class="col-xs-2">
<label for="ex1">Cantidad</label>
<!-- DEBE TENER UN DDL PARA LA BASE DE DATOS-->
<input class="form-control" id="txtCantidad" type="text">
</div>
<div class="col-xs-2">
<label for="ex1">Subtotal</label>
<!-- DEBE TENER UN DDL PARA LA BASE DE DATOS-->
<input class="form-control" id="txtSubtotal" type="text">
</div>
<div class="col-xs-2">
<button class="btn btn-default" type="submit" id="btnlistar">+</button>
</div>
</div>
</div>
</form>
</body>