Page 1 of 1

javaScript/ label problems

Posted: Fri Jan 09, 2015 8:32 pm
by Vilis Jurgaitis

Hello, I have a problem with javaScript.
I use two pages, that are named "Startas" and "Rezultatas" accordingly.
The first page has two inputs and a button, and when I push it it should get the two inputs and add them if they are two-digit numbers, but instead it just shows those two numbers on the second page in the LABEL component. I would like to know how should i write the code to make the label element show the sum of the two inputs, instead of those inputs
codevar pirmas = Appery('Input1').val();
var antras = Appery('Input2').val();
var rezultatas;
if (((10<=pirmas) && (pirmas <= 99)) && ( (10 <= antras) && (antras <= 99)) )
{
rezultatas = (pirmas + antras);
}
else
{
rezultatas="Iveskite tik dvizenklius skaicius&quot
}

localStorage&#46;setItem('Atsakymas' , rezultatas);
Appery&#46;navigateTo('Rezultatas' , {});
/code
and the second page code:
prevar atsakymas = localStorage&#46;getItem('Atsakymas');
Appery('Output')&#46;text(atsakymas);
/pre


javaScript/ label problems

Posted: Fri Jan 09, 2015 8:55 pm
by Vilis Jurgaitis

when i try "*" "-" and "/" operators it works just fine, could it be probelms with my keyboard/language settings?


javaScript/ label problems

Posted: Sat Jan 10, 2015 9:06 am
by Alena Prykhodko

Hello Vilis,

Your code is not correct, you are trying to concatenate strings instead of numbers, should be:

  1. On button click event add Run JS:

    precode
    var pirmas = parseInt(Appery('Input1')&#46;val());
    var antras = parseInt(Appery('Input2')&#46;val());
    var rezultatas;
    if (((10<=pirmas) && (pirmas <= 99)) && ( (10 <= antras) && (antras <= 99)) )
    {
    rezultatas = (pirmas + antras);
    }
    else
    {
    rezultatas="Iveskite tik dvizenklius skaicius&quot
    }

    alert(rezultatas);

    localStorage&#46;setItem('Atsakymas' , rezultatas);
    Appery&#46;navigateTo('Rezultatas' , {});/code/pre

  2. Create Storage variable Atsakymas http://devcenter.appery.io/documentat...

  3. On second page on Load event this code:

    prevar atsakymas = localStorage&#46;getItem('Atsakymas');
    Appery('Output')&#46;text(atsakymas);/pre

    In case you have problems with JavaScript, first try to debug it.
    Actually, custom code is outside the scope of support.