Page 1 of 1

calculating values from select component

Posted: Fri Mar 14, 2014 2:13 pm
by Hunter Hansen

I have a rating scale select component for 2 questions (item1, item2). the values are numbers. I want to add numbers but when I do I get NaN. Heres my javascript.

var n1 = parseInt(Appery("item1").val()), n2 = parseInt(Appery("item2").val());
Appery("totalnum").text(n1+n2);


calculating values from select component

Posted: Fri Mar 14, 2014 3:36 pm
by Nikita

Hello,

Which value is in item1 component?
Please display this value with alert():

alert(Appery("item1").val());


calculating values from select component

Posted: Fri Mar 14, 2014 4:07 pm
by Hunter Hansen

"the page at appery.io says: "

blank

you can see it here
http://appery.io/app/mobile-frame?src...


calculating values from select component

Posted: Fri Mar 14, 2014 5:25 pm
by Nikita

Hi,

Your problem is that you are using the custom component. Therefore, you should use custom component name when you refer to "select" element. In other words, just replace this code:

var n1 = parseInt(Appery("item1").val()), n2 = parseInt(Appery("item2").val());

with:

var n1 = parseInt(Appery("item1_item1").val()), n2 = parseInt(Appery("item2_item1").val());


calculating values from select component

Posted: Fri Mar 14, 2014 5:28 pm
by Hunter Hansen

thank you!!!!!!!!!!!!!!!!!!!!!!