I have the following function which I call both by keyboard and by a href simulating a button but the detail happens because when I execute it by keyboard it changes the value of ('#total') but when I execute it by clicking it does not .
function calcular_total(){
$('#items tr').each(function () {
var cantidad = $(this).find('td').eq(2).html();
var precio = $(this).find('td').eq(3).html();
if(typeof cantidad != 'undefined' && typeof precio != 'undefined')
{
var cantidad = $(this).find('td').eq(2).html();
var precio2 = $(this).find('td').eq(3).html();
var preciocorregido = parseFloat(precio2);
var cantidadcorregido = parseInt(cantidad);
var total1 = cantidadcorregido * preciocorregido;
var total = parseFloat($('#totaloculto').val());
total += parseFloat(total1);
$('#totaloculto').val(total);
$('#total').text(total);
}
});
};
This way I call it by keyboard
$('#precio').keypress(function(e){
if (e.which == 43){
agregar_item();
//e.preventDefault();
};
});
and in this way I call him by the
<a onClick="agregar_item(); return false;" class="btn-floating green btn-large"><i class="material-icons">add</i></a>
The function add_item () calls the function calculate total I have verified that it does everything except change the value of the inputtext '#total'