# How can I get the value of a text element?

**URL:** <https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577>\
**Category:** Need help\
**Created:** [July 19, 2021, 2:12pm UTC](https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577 "2021-07-19T14:12:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron2](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ron2/32/62072_2.png) [@ron2](https://forum.bubble.io/u/ron2)\
**Post date:** [July 19, 2021, 2:12pm UTC](https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577/1 "2021-07-19T14:12:16Z")

</div>

Hi!

I want to extract the value of a text element so that I can use it in a workflow to set the state of another element. I know you can use Inputs in place of text elements and get access to their contents. But the problem here is that I need to set the content of the text element using JavaScript, and I cannot see how you could set the content of an Input with JavaScript.

Program flow looks like:

- Run some js in an HTML box with script tags.

- That js sets the content of Textbox A (with element ID “textboxA” with something like:  
document.getElementById(“textboxA”).innerHTML = window.accountId;

- Next, want to extract and use the value of window.accountId that has been injected into TextBox A in a workflow step (as a parameter accessing an API, for example)

Just cannot figure out how to get at that text that has been placed inside TextBox A. I have tried Toolbox, but have not been successful. May be I am not adept enough at using it!

Thanks for any help in this. Any technique that gets me what’s inside Textbox A for use in further workflow steps would very welcome.

---

<div class="post-metadata">

**Author:** ![myflappd](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@myflappd](https://forum.bubble.io/u/myflappd)\
**Post date:** [July 19, 2021, 3:02pm UTC](https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577/2 "2021-07-19T15:02:29Z")

</div>

Can you set a text based state on page using JavaScript?

---

<div class="post-metadata">

**Author:** ![AdamT](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@AdamT](https://forum.bubble.io/u/AdamT)\
**Post date:** [July 20, 2021, 1:07am UTC](https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577/3 "2021-07-20T01:07:41Z")

</div>

Hey @ron2

I found this [video](https://vimeo.com/278023158) helpful when setting up toolbox, and perhaps I have a solution for you below:

**Here’s my setup:**

1. Create your HTML element (not sure what your functions are).  
– My script just creates a var x with a string of “test test test”  
– Put your variable into a function that can be pulled out later with the JavascripttoBubble element, in my case I called this bubble\_fn\_ **function** (this will make more sense later).

 ![Screen Shot 2021-07-19 at 5.53.26 PM](https://us1.discourse-cdn.com/bubble/original/3X/3/6/36cc35a4d5a402a8307ded33baec310efa72e500.png)

* * *

1. Add a JavascripttoBubble element to the page from the Toolbox elements.  
– Set up a function name that matches whatever was in your HTML script, in my example: **function**.  
– Check _publish value._ (otherwise I don’t think you will see it as an element with a value in Bubble).

> Toolbox always has “bubble\_fn\_” before the name of the function and pulls out the first parameter AFAIK.

 ![Screen Shot 2021-07-19 at 5.55.31 PM](https://us1.discourse-cdn.com/bubble/original/3X/6/7/67d56a003f51c4e5f97d32338f7fb169b89c25d6.png)

* * *

1. Set up your text box or input (I added both on the page) = JavascripttoBubble A’s value.

 ![Screen Shot 2021-07-19 at 5.59.17 PM](https://us1.discourse-cdn.com/bubble/original/3X/c/b/cb1d776ce9e0566894ed20b02a8e36a7ca9d2009.png)

* * *

1. Set up a workflow to populate your state. In my case I just made a button that updates the state.

 ![Screen Shot 2021-07-19 at 6.02.28 PM](https://us1.discourse-cdn.com/bubble/original/3X/b/0/b06e34eb10f44edd18971166f957e6f8a675decb.png)

* * *

**Result**

(The state is empty before pressing the button)

 ![Screen Shot 2021-07-19 at 6.03.00 PM](https://us1.discourse-cdn.com/bubble/original/3X/d/8/d8af48a50c0585a35b74676736f9054757051e54.png)

* * *

Hope this helps and that I understood your requirements right,

Adam

---

<div class="post-metadata">

**Author:** ![ron2](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ron2/32/62072_2.png) [@ron2](https://forum.bubble.io/u/ron2)\
**Post date:** [July 21, 2021, 3:54pm UTC](https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577/4 "2021-07-21T15:54:52Z")

</div>

Adam, thank you for this detailed answer!

I wasn’t quite able to make do what I need to do, though. No doubt due to my insufficent explanation. The textbox and input in this example are both populated by the js in the HTML, surfaced in bubble by the JavascriptToBubble plugin.

The problem is getting at the contents of a texbox or when it has been populated in some other way. For example, if I were to create a bubble text elementand put the words “Here is the text.” inside of it, how can I get at that string, using JS to bubble, for example.

If the result published by the JS to Bubble plugin is used to populate the text or input elements, then we could simply use the JS to Bubble published value in the workflow, without reference to the text or input elements.

So perhaps I have been too convoluted in my description. More simply stated: how do I get the text in a textbox available for use in a workflow? Hope that makes sense.

Will keep hacking it, see if there’s a way to leverage the great example code you provided.

Thank you!

Ron

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [September 27, 2021, 2:12pm UTC](https://forum.bubble.io/t/how-can-i-get-the-value-of-a-text-element/160577/5 "2021-09-27T14:12:21Z")

</div>

Closed on September 27, 2021, 2:12pm UTC

This topic was automatically closed after 70 days. New replies are no longer allowed.
