Search code examples
javabuttontextboxlabelgoogle-app-maker

Google App Maker - Button onClick read and sum up from textbox to a label


i´m stuck on a maybe simple function.

I have 3 widgets : One TextBox, One Label, and a Button.

What I need is :

OnClick the Button --> Reads the value of the textbox (number) and adds this amount to the current value of the Label widget.

For example : current value of the Label = 500 ,write in the text box 300 and click the button , the value of the label changes to 800.

Here are screenshot,and my not working code.

I appreciate every help.

Greetings

var einlesefeld =  app.currentPage.descendants.TextBox179;
var gesamtnummer = app.currentPage.descendants.Label161;

gesamtnummer.value = gesamtnummer.value + einlesefeld.value;

Solution

  • This is the exact same problem I had when I first started with App Maker. To understand why this is not working, I went over the Widgets API Documentation. Unlike the TextBox widget, the Label widget contains a text property and not a value property; Hence it is not working. Please change it to this:

    var einlesefeld =  app.currentPage.descendants.TextBox179;
    var gesamtnummer = app.currentPage.descendants.Label161;
    
    var updatedValue = Number(gesamtnummer.text) + Number(einlesefeld.value);
    gesamtnummer.text = updatedValue.toString();