David Lim
Posts: 0
Joined: Wed Mar 12, 2014 3:58 am

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

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);

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

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

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

David Lim
Posts: 0
Joined: Wed Mar 12, 2014 3:58 am

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

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

Hello!

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

Return to “Issues”