# What is the name of user input for a text area?

**URL:** <https://community.plotly.com/t/what-is-the-name-of-user-input-for-a-text-area/59169>\
**Category:** Dash Python\
**Created:** [December 9, 2021, 3:35pm UTC](https://community.plotly.com/t/what-is-the-name-of-user-input-for-a-text-area/59169 "2021-12-09T15:35:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertpfaff](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@robertpfaff](https://community.plotly.com/u/robertpfaff)\
**Post date:** [December 9, 2021, 3:35pm UTC](https://community.plotly.com/t/what-is-the-name-of-user-input-for-a-text-area/59169/1 "2021-12-09T15:35:15Z")

</div>

I know this seems like an easy question, but I cannot find the answer.

I am switching from Streamlit to Dash, and that’s part of the problem. I am very new to Dash, only in the past few days.

Still, the answer to this one should be obvious.

In this text area, the user pastes a cooking recipe. I need to iterate over the lines in that recipe with a for loop. When I use the “value” to identify the submitted recipe, it does not work. When I use the “id”, it does not work. I have tried a dozen different, seemingly apparent ways to identify the text in the input textarea. I cannot make it work.

So how should I identify the contents of a text area to process it with a for loop?

Here is the code for the textarea:

```auto
app.layout = html.Div([
    dcc.Textarea(
        id='textarea-state-example',
        value='recipe',
        style={'width': '1000%', 'height': 200},
		placeholder='Please paste your recipe here.',
		className='recipe-textarea',
		contentEditable='true'
		
    ),
    html.Button('Submit', id='textarea-state-example-button', n_clicks=0),
    html.Div(id='textarea-state-example-output', style={'whiteSpace': 'pre-line'})
])

```

Here is the for loop:

```auto

with open ("recipe_contents.txt", "w", encoding='utf-8') as recipe_contents:
	for line in recipe:
		recipe_contents.write(line)
		print("Recipe contents witten to file.")

```

Thank you.

---

<div class="post-metadata">

**Author:** ![jlfsjunior](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jlfsjunior/32/16061_2.png) [@jlfsjunior](https://community.plotly.com/u/jlfsjunior)\
**Post date:** [December 9, 2021, 4:45pm UTC](https://community.plotly.com/t/what-is-the-name-of-user-input-for-a-text-area/59169/2 "2021-12-09T16:45:47Z")

</div>

Hi,

You should use “value”, but in a callback. Something like:

```auto
@app.callback(
    Output('textarea-state-example-output', 'children'),
    Input('textarea-state-example-button', 'n_clicks'),
    State('textarea-state-example', 'value')
)
def update_recipe(n_clicks, textarea_value):
    if n_clicks > 0:
        with open ("recipe_contents.txt", "w", encoding='utf-8') as recipe_contents:
             recipe = textarea_value.split("\n")
	     for line in recipe:
		 recipe_contents.write(line)
	 	 
        return "Recipe contents witten to file."
  

```

P.S: Not sure if you want width = 1000% or if it was a typo…

---

<div class="post-metadata">

**Author:** ![robertpfaff](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@robertpfaff](https://community.plotly.com/u/robertpfaff)\
**Post date:** [December 9, 2021, 5:42pm UTC](https://community.plotly.com/t/what-is-the-name-of-user-input-for-a-text-area/59169/3 "2021-12-09T17:42:18Z")

</div>

Yep. that worked. Thank you.

Since that same callback already existed in my code preceding the function, I don’t understand how it made a difference.

Granted, I have much to learn about callbacks, so I yield to a higher power on that one.

I also had to move the return statement out of the loop or it broke after the first line. The 1000% was a typo though I was trying to figure out how to reduce the textarea to 80% without throwing the Submit button out of alignment.

But I will save that lesson for another day.

Thanks again.

Robert

In case this is helpful to someone in the future:

```auto
def update_recipe(n_clicks, value):

    if n_clicks > 0:

        with open("temp/recipe_contents.txt", "w", encoding='utf-8') as recipe_contents:

            recipe = value.split('\n')

            for line in recipe:

                print(line)

                recipe_contents.write(line)

                recipe_contents.write('\n')

            return "Recipe contents written to file."

```
