Hello! In our last lesson, you successfully configured a JavascriptToBubble element to capture a result from your embedded calculator and save it to your database. You've built a solid communication channel from your JavaScript tool into Bubble.
Today, we're building the other lane of the highway. We'll complete the integration loop by learning how to send data from your Bubble application into your embedded JavaScript tool. This is the final piece of the puzzle for achieving the "deep integration" you're aiming for. By the end of this lesson, you'll be able to create a Bubble button that takes values from input fields on your page, sends them to your JavaScript calculator for processing, and then receives the result back to be saved in your database—a complete, two-way data flow.
The Run javascript Action
The key to sending data to your JavaScript is a workflow action provided by the Toolbox plugin: Run javascript. While the JavascriptToBubble element listens for data coming from JS, the Run javascript action actively pushes data into it.
The most powerful feature of this action is its ability to directly embed Bubble's dynamic data into the script. You don't need complex methods to find elements on the page; you can literally write your JavaScript code and insert a value from a Bubble input field or the database right where you need it.
This is a common challenge for developers, as shown in this Bubble forum thread. The user wanted to get data from their database into a JavaScript variable.
This forum post perfectly illustrates the problem and the surprisingly simple solution that Bubble provides.
First, read the original question to understand the user's problem: they have data in Bubble and need to get it into a JavaScript variable, expressed as var bad_json = ?. Then, review the solution they found, which highlights the "Insert Dynamic Data" popup available right inside the workflow action.
As the forum post reveals, Bubble makes this incredibly straightforward. The "Insert dynamic data" button lets you place any data your app has—an input's value, the current user's email, a thing from the database—directly into your code.
Here is an image showing this in action. Notice how broken json's value is blue, indicating it's dynamic data from Bubble being assigned to the bad_json JavaScript variable.

A Complete Walkthrough
To see how this works from start to finish, we can turn back to the excellent video by Jacob Gershkovich that we used in the previous lessons. He demonstrates this exact process of using Bubble inputs to feed a JavaScript calculation.
The Bubble.io Toolbox Plugin | How to save a value from Javascript to Bubble | Bubble.io Tutorials
This video walks through the entire two-way data flow, starting with defining the inputs and ending with sending the result back to Bubble.
First, for a quick refresher on how JavaScript functions use parameters (or arguments), you can watch the segment from this section on functions. This will help you understand how values are passed around within the code. Next, watch the core demonstration from this part. This is the most important section for today's lesson. Pay close attention to how he uses the Run javascript action and inserts the values from different Bubble inputs to define his number1, number2, etc., variables. Finally, watch how he completes the loop from this final segment. He defines a solution variable, and then calls the bubble_fn_do_math(solution) function. This second part should be familiar from our last lesson—it's how the calculated result is sent back to the JavascriptToBubble element.
This process gives you a powerful and scalable architecture. Your embedded HTML element can contain a "black box" of pure JavaScript logic, and your Bubble interface can be responsible for providing the inputs and handling the outputs.
Exercise: Building the Two-Way Bridge
Let's modify the calculator page to create a full, two-way integration. You will add Bubble inputs and a Bubble button to control the JavaScript calculator.
1. Update the UI
-
On your tool page, add two Input elements. Name them "Input A" and "Input B". Set their
Content formattoInteger. -
Add a Button element below the inputs. Change its text to "Calculate".
-
You can now edit your HTML Element and remove the input fields and the "Send Result to Bubble" button from inside the HTML code. Your HTML should now only contain the core JavaScript logic. Update your
<script>tag to look something like this, leaving the calculation part empty for now. We will generate the full script via the workflow.<script> function performCalculation(numA, numB) { // The `Run javascript` action will put the calculation logic here. } </script>Don't worry about this function for now, it's just a placeholder. The main logic will live in the workflow.
2. Create the "Calculate" Workflow
- Select the "Calculate" button and click Start/Edit workflow.
- Add a new action: Plugins > Run javascript.
3. Configure the Run javascript Action
-
Inside the script box, you will write the code that takes the input values, performs the calculation, and sends the result back to Bubble.
-
Click inside the script box and construct the following code. Use the Insert dynamic data feature to add
Input A's valueandInput B's value.// 1. Define variables using data from Bubble inputs var numberA = Input A's value; var numberB = Input B's value; // 2. Perform the calculation var result = numberA * numberB; // Or any other operation you like // 3. Send the result back to Bubble using the function from the JavascriptToBubble element bubble_fn_value(result);Note: Replace
bubble_fn_valuewith whatever your function is named (e.g.,bubble_fn_aorbubble_fn_calculator). You can check this in the properties of yourJavascriptToBubbleelement.
4. Test the Full Loop
- Go to Preview mode.
- Enter a number into Input A and Input B.
- Click your "Calculate" button.
- The workflow will run your JavaScript, which calculates the result and sends it back to your
JavascriptToBubbleelement. - The
When JavascriptToBubble event is triggeredworkflow you built in the last lesson should then fire automatically, saving the new result to yourCalculationLogin the database. - Check your App Data to confirm that the new log entry was created successfully.
You have now created a complete, two-way communication channel! Data flows from Bubble's UI into a JavaScript process, and the result flows back into Bubble's database.
Conclusion
Mastering this two-way data flow is the cornerstone of building the deeply integrated, scalable tool platform you envisioned. You are no longer limited to just embedding isolated widgets; you can now build seamless experiences where your Bubble application and custom code work together as one.
Let's recap the key takeaways from this lesson:
- The
Run javascriptworkflow action is used to execute JavaScript code and send data to it. - You can use the Insert dynamic data button to place values from your Bubble app (inputs, database things, etc.) directly into your JavaScript code as variables.
- By combining
Run javascriptwith theJavascriptToBubbleelement, you can create a full, two-way communication loop: send data from Bubble to JS for processing, and then send the result back to Bubble to be stored or used in other workflows.
Now that you have the essential skills for integrating custom tools, our next focus will be on managing your growing collection of tools. In the next lesson, we will begin a new module on content management by designing and building a private admin page to add, edit, and manage all the tools on your platform.