2
Hello,
I’m having a problem recovering the global variable total
in a script.
In an Alert inserted in the same scope it is displayed normal, but in a declaration it is not returned, it appears Undefined. follows the excerpt:
preco = "";
qtd = "";
total = "";
function keypressed(obj, e, f) {
var tecla = (window.event) ? e.keyCode : e.which;
preco = f;
qtd = tecla - 48;
total = qtd * preco;
if (tecla == 8 || tecla == 0 || tecla == 13)
return true;
if (tecla < 48 || tecla > 57)
return false;
}
$("#confirma").confirm({
title: "Confirmação",
ERRO >>> text: "O valor total é R$" + total + ", confirmar venda?",
confirm: function(button) {
button.fadeOut(2000).fadeIn(2000);
Aqui aparece normal > alert(total);
},
cancel: function(button) {
button.fadeOut(2000).fadeIn(2000);
alert("Venda não realizada.");
},
confirmButton: "SIM",
cancelButton: "NÃO"
});
text:"O valor total é...
the value does not appear.
Any help is worth. vlw.
tried to change his statement with var before? Like this: var total = "";
– Leonardo Costa
I tried yes, I even tried to do the calculation in global scope but from the same error, the variable itself has value but is not returned at that specific position. other tests I did was to put a logo value in the variable declaration. ai works, but I need this value to be dynamic and not predefined.
– Lucas Finey
Already tried to convert to integer before performing multiplication?
– Renato Tavares
I tried now, by giving me the tip, thanks, but also did not work.
– Lucas Finey
I don’t know this syntax
ERRO >>>
, put the code exactly the way you did and to comment lines use the/**/
or//
– Guilherme Nascimento