How to take the return of a function and throw it into a wappler variable?

I have a question I believe it is simple, I have a function and an example to see how it works:

function show(n1, n2) {
     var sum = n1 + n2

     return sum
}

I would like to take the result of the sum and pass it to a Wappler variable where I can manipulate this variable in the Wappler environment, how could I do that?

The variable would be this:

<dmx-value id="soma"></dmx-value>

how do I put the function return for this variable?
Thank you so much guys

Maybe check the following article it will help you understand how the things work:

In this specific case your code should become:

function show(n1, n2) {
    var sum = n1 + n2
    dmx.parse('soma.setValue('+sum+')');
}
1 Like

One question Teodor, I was testing dmx.parse but it doesn’t work on pages only in layouts, is there a way to use it inside pages too?

When I use it within the pages, it does not pick up the values only in the layout that works.
Thanks.

It usually needs content. first.

I.e.

dmx.parse('content.soma.setValue('+sum+')');
1 Like

It worked out that way, you’re awesome, I didn’t know I needed to use the content at the beginning.

Thank you very much