and make it usable via the Expression element from the Toolbox Plugin. But I failed.
What must the JS code or what must the Expression be? I only managed to output the result via innerHTML as shown in the example. However, I only need the value itself to be able to use it via the Expression element.
The Debugger reports that the myVariable is not defined.
Now I have to put <div class="print"></div> somewhere to show the myVariable value. That works. But I want to be able to put only the value itself into the myVariable expression in order to handle it as I like (e.g. formatting, save to database).
After downloading the Toolbox plugin you will notice that you have a new element to drag and drop into your editor, called JavaScript to Bubble. Drag and drop this element. This is the element you will use to receive the variable from your JavaScript snippet and make it visible to Bubble.
Note that in my case, I am expecting to receive a NUMBER as variable.
You will use the function “bubble_fn_xxxxx ()” to pass the result to your Bubble element. In our case, the function is “bubble_fn_text ()”. As you can see, after I run the code, I can load the result anywhere I want…
is there a difference using the “Expression” element or the “Javascript to Bubble” element in combination with a workflow? Is it always best to initiate JS code via a workflow on page load?
My example above also works with the “Expression” and “HTML” element. With the exception that I can’t “read” the myVariable from this JS function:
I’ve implemented a few different options (on elements, with json in/out, …) and the one that I like the most is the one where I place an workflow action (runs on workflow request) or element (every time something changes), where the javascript runs. Then I have a set of “input elements” that are triggered “changed” by the javascript when the respective value is updated. There are several “input elements” that correspond to each type.
The Javascript to Bubble is used basically to pass variables from Bubble to your JS code and vice-versa, allowing you to perform complex operations in JS and send the result back to Bubble in just a second.
If you are looking to elements where you can just write some JS to make adjustments or add some functionality to your app, you can use whatever you want, such a “HTML element”, as you said.