How to use JavaScript Variables Values with App Connect

I am following this tutorial from documentation:

https://docs.wappler.io/t/using-app-connect-with-javascript-functions/15765

Fist time I am trying this: I want to pass the height from a div to another div I am creating this function.

<script>
    var div = document.getElementById('image-test');

    // Get the height of the div (including padding, border, but not margins)
    var cloneHeight = div.offsetHeight;

    dmx.app.set('cloneHeight', cloneHeight);
 </script>

But I get this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'set')

Wha I am making wrong?? Any help will be welcome.

Your script is (probably) being executed before Wappler has a chance to load, so dmx.app.set() doesn't exist yet

How to test if this is the case? Go to your browser console and type that dmx.app.set expression, if it works then the theory is confirmed (because by the time you go to the browser console Wappler is already loaded)

Use DOMContentLoaded:

Maybe this can help:

Is any way to fix this?

Envolving in a function and calling with a flow?

1 Like