Page 1 of 1

Hi i trying to do a Javascript where it continue to calculate if the user left one textbox blank. But i unable to do so

Posted: Fri Mar 28, 2014 5:17 am
by David Lim

var Item1 = parseInt(Appery("TextAmount1").val()),
Item2 = parseInt(Appery("TextAmount2").val()),
Item3 = parseInt(Appery("TextAmount3").val()),
Item4 = parseInt(Appery("TextAmount4").val());
var total;
total = 0;
if(Item1.val() != "")
{
total = total + Item1;
}
if(Item2.val() != "")
{
total = total + Item2;
}
if(Item3.val() != "")
{
total = total + Item3;
}
if(Item4.val() != "")
{
total = total + Item4;
}
else
{
alert("Please buy something");
}
Appery('labelresult').text(total);


Hi i trying to do a Javascript where it continue to calculate if the user left one textbox blank. But i unable to do so

Posted: Fri Mar 28, 2014 5:46 am
by Illya Stepanov

Hi David,

You tried parse in integer empty field. And the value of it parsing is NaN (Not a number).
Look here more information: http://stackoverflow.com/questions/11...

Please use:
pre
if(isNaN(Item1.val()))
/pre
instead of:
pre
if(Item1.val() != "")
/pre


Hi i trying to do a Javascript where it continue to calculate if the user left one textbox blank. But i unable to do so

Posted: Fri Mar 28, 2014 6:19 am
by David Lim

var Item1 = parseInt(Appery("TextAmount1").val()),
Item2 = parseInt(Appery("TextAmount2").val()),
Item3 = parseInt(Appery("TextAmount3").val()),
Item4 = parseInt(Appery("TextAmount4").val());
var total;
total = 0;
if(isNaN(Item1.val()))
{
total = total + Item1;
}
else if(isNaN(Item2.val()))
{
total = total + Item2;
}
else if(isNaN(Item3.val()))
{
total = total + Item3;
}
else if(isNaN(Item4.val()))
{
total = total + Item4;
}
else
{
Appery('labelresult').text("Please Buy something in the market");
}
Appery('labelresult').text(total);

Nothing show up :/ is there a mistake i made?


Hi i trying to do a Javascript where it continue to calculate if the user left one textbox blank. But i unable to do so

Posted: Fri Mar 28, 2014 2:45 pm
by Maryna Brodina

Hello!

Try preisNaN(Item1)/pre instead preisNaN(Item1.val())/pre