Michael P. Eckhardt
Posts: 0
Joined: Thu Jan 23, 2014 8:55 pm

two inputs, one label for output (calculation)

I have two input fields for values x and y, one button and a label, which should show the value of x+y after pressing the button.

I am able on pushing the button to get the values of both input fields and store them in appropriate variables.
Also I can change the text in the label according to these two values (x and y).

But I do not know where I need to declare the variable z, assign the value of z=x+y and use the value of z to output it into my label.

Who can help me out (or point me where I can find the appropriate info?)?

Thanks!

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

two inputs, one label for output (calculation)

Hello! It can be done with custom JS on button click. On button click add JS where you retrieve input values, sum them and set result in Label.

Michael P. Eckhardt
Posts: 0
Joined: Thu Jan 23, 2014 8:55 pm

two inputs, one label for output (calculation)

Hi Maryna,

thanks for the feedback.

Of course this is done via JS, but where do I enter the relevant coding?
In the tutorial I can only find a section, where I can enter my name and have an output like ("Hello "+name). Where and how would I enter a function to calculate and change label value?

So far I have 4 events on the button.
1 each for retrieving the inputs values.
1 for calculating the sum
1 for changing the label's value

I think the last one can be omitted.

But the calculation of the sum goes somehow like this:

function calcsum() {
var z = x+y;
document.setData("lbl_output", z);
}

Still the label is not updated.

What am I missing?

Thanks.
Michael

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

two inputs, one label for output (calculation)

Delete all actions, you need only Run JavaScript action on button click with the following code: prevar n1 = parseFloat(Appery("input1Name").val()), n2 = parseFloat(Appery("input2Name").val());
Appery("labelName").text(n1+n2); /prewhere input1Name, input2Name, labelName - component names on page.

Michael P. Eckhardt
Posts: 0
Joined: Thu Jan 23, 2014 8:55 pm

two inputs, one label for output (calculation)

Thanks!

This did work.

Cheers
Michael

iPsyc Videos
Posts: 0
Joined: Thu Mar 13, 2014 7:46 pm

two inputs, one label for output (calculation)

I tried Mayna's code, but it's not calculating my simple calculator total. I have 2 inputs (number1, number2). and a button to run javascript on click (copied from her post). the labelName is "lablemytotal" and is a Lable. Any suggestions?

Hunter

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

two inputs, one label for output (calculation)

Hello,

Are there any errors in console?

iPsyc Videos
Posts: 0
Joined: Thu Mar 13, 2014 7:46 pm

two inputs, one label for output (calculation)

Uncaught SyntaxError: Unexpected identifier /app/view/cd98d2b1-88bf-4382-b52c-c640f2aceb25/startScreen.js:77
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery-1.9.1.js:3345

iPsyc Videos
Posts: 0
Joined: Thu Mar 13, 2014 7:46 pm

two inputs, one label for output (calculation)

never mind, had some junk code I forgot about on page load. thanks

iPsyc Videos
Posts: 0
Joined: Thu Mar 13, 2014 7:46 pm

two inputs, one label for output (calculation)

I did not know about the console, so thanks NIkita!

Return to “Issues”