Page 1 of 2

Change UI Element valaue

Posted: Fri Sep 20, 2013 2:15 pm
by Newby

Good Day.
I have screen where the user will input data financial data and on clicking the 'Calculate' button needs to calculate the 'installment' and show in 'Result' field.
Here is the code that is not working....

Can you please help.

var princ = Appery("loan").value();
var term = Appery("months").value();
var intr =Appery("rate").value() / 1200;
var getval = Appery("pay").text();
var payment = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
Appery('pay').text(payment);


Change UI Element valaue

Posted: Fri Sep 20, 2013 2:21 pm
by maxkatz

What exactly doesn't work? Do you know until line it does work?


Change UI Element valaue

Posted: Fri Sep 20, 2013 2:26 pm
by Newby

Hi Max,
I would expect the result of the calculation to show in textfield "pay" - get nothing happens when clicking on the caculate button.

When debugging i get a message "Uncaught error: Object has not method 'value'"

Thank you


Change UI Element valaue

Posted: Fri Sep 20, 2013 2:27 pm
by Newby

var princ = Appery("loan").value();

When debugging i get a message "Uncaught error: Object has not method 'value


Change UI Element valaue

Posted: Fri Sep 20, 2013 2:38 pm
by maxkatz

Please check the API here: http://docs.appery.io/javascript-api/

When using Appery(..) function, to read a value from an input component would be:

code
Appery('component_name').val();
/code

Appery(..) is just a small wrapper on top of jQuery.. for any API available, please refer to jQuery/jQuery Mobile docs.


Change UI Element valaue

Posted: Fri Sep 20, 2013 2:44 pm
by Newby

Hi Max. Thanks for the docs, but i have used them as reference already :)..

var princ = Appery("loan").value();

In this line i declare a variable 'princ' and wants to assign the value from the input field 'loan' to the variable - but is getting error as mention earlier.


Change UI Element valaue

Posted: Fri Sep 20, 2013 3:21 pm
by maxkatz

It should be: Appery("load").val();


Change UI Element valaue

Posted: Fri Sep 20, 2013 7:40 pm
by Newby

Hi Max,
The field name is 'loan'
I want the value from input field 'loan' to be assigned to var princ....

Var princ = appery("loan").value

After the calculation, i want the value of the calcultion to be assigned to input field 'pay'

It is just a on screen calcultion and dont need to store any values once i move away from the screen.


Change UI Element valaue

Posted: Fri Sep 20, 2013 8:00 pm
by Maryna Brodina

Hello! Try this code:
prevar princ = Appery("loan").val();
//some calculations here
Appery("pay").val(princ);/pre


Change UI Element valaue

Posted: Mon Sep 23, 2013 7:34 am
by Newby

Hi Guys,
I have tried the suggestion from Marina as well

"var princ = Appery("loan").val();
//some calculations here
Appery("pay").val(princ);"

...and it is not working.

The script needs to run on the click event....but i get an error message that the "Object doesn't support property or method 'value'"

Do i need to define \ declare anything else?
I have attached a screenshot of the debug screen.

My java script currently is

var princ = Appery("loan").value();
var term = Appery("months").value();
var intr =Appery("rate").value() / 1200;
var getval = Appery("pay").value();
var payment = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
Appery('pay').value(payment);

Image