Add dynamic values from text boxes

Hi,

With the code below I can add the static contents of two text boxes:

var y = $w("#text17").text;
var z = $w("#text19").text;
var x = +y + +z  ;

console.log("Y is", y, "Z is", z, "and Xsum is", x)
    $w("#answer").text = String(x);

These two text boxes though have dynamic numerical values. How can I change the code above not to add the static content of the text boxes but the actual numbers loaded dynamically every time?

Thanks.

Are you trying to add (addition) the two number??
If it is →

var y = $w("#text17").text;
var z = $w("#text19").text;
var x = Number(y) + Number(z);

console.log("Y is", y, "Z is", z, "and Xsum is", x)
    $w("#answer").text = String(x);

JavaScript Number() Method.

I’m trying to do addition, yes, like in the code I provided. Only that the values in #text17 and #text19 are not static but change dynamically (say they count some stock in an inventory that changes daily).

I don’t understand the link you sent me how it is related. I don’t want to make a conversion. And your replacement code does not work. You replaced my ( +y + +z ) with number(y) + number(z) but the result is the same. It still adds the placeholder values, not the computed ones.

@russian-dima ? maybe?

I did not really understand what you want to achieve, so i just make here some examples, perhaps it fits to your imaginations…

example-1:

var counter = 1
var  y  =  $w("#text"+counter).Text ; 


example-2:


var myArray = [text1, text2, text3, title22, title33, expression1]
var  y  =  $w("#"+myArray[3]).Text ; 

@russian-dima Hi, I just want to add (addition) two text boxes whose value changes dynamically.

Example: in my shop, I sell “motherboards” and “vga”. Today I sold 12 and 20 respectively. The “12” and “20” is counted automatically with .count() from the database (like the examples I was struggling yesterday, if you remember). Okay. So 12 and 20 are displayed inside ‘text1’ and ‘text2’ (with .eq() and .count(), etc).

Now, I want to ADD the ‘text1’ with ‘text2’ and get something like:

var total = text1 + text2
console.log(“Total Hardware Sales today:”, total)// where total = 20+12=32.

I code I mentioned above works perfectly if you are trying to add the numbers in the two texts

var y = $w("#text17").text;
var z = $w("#text19").text;
var x = Number(y) + Number(z);

console.log("Y is", y, "Z is", z, "and Xsum is", x)
    $w("#answer").text = Number(y) + Number(z);

@ajithkrr As I replied above, your code works perfectly if one has static values in these text boxes. If the value is calculated from a dataset, then it doesn’t work and still adds up the placeholder/static text. I wish it worked. Thank you for your effort though.