# Input from Text Area/Input Box Etc upon pressing Enter Key and then Text getting Cleared

**URL:** <https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774>\
**Category:** Ignition\
**Created:** [December 17, 2019, 6:57pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774 "2019-12-17T18:57:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 17, 2019, 6:57pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/1 "2019-12-17T18:57:25Z")

</div>

Hi All,

Can you guys please tell me how to deal with the sending input values upon pressing the Enter Key? For example, I have an input box, and a display label. The label shows whatever is input via the input box, but after typing my string in the box, I have to click somewhere else in order for it to be passed through and displayed eventually. I want to Press Enter Key, and the values should pass/

Secondly, Upon pressing the Enter Key, I want it to clear the field as well, as if its read for next input or whatever, but the main thing is that the Input Text Field should be cleared. How can this be done?

Thanks

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 17, 2019, 8:43pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/2 "2019-12-17T20:43:19Z")

</div>

The best way is to handle this with a propertyChange Event:

Right-click your Text Field Input and select “Scripting”.

 ![02%20PM](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6c53b37da938e5cef02983f11e94aae15fd5b7bc.png)

This will, however, prevent your user from ever supplying an empty string `""` as a value.

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 17, 2019, 9:34pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/3 "2019-12-17T21:34:01Z")

</div>

Thanks! Anyway to get around that as well Cmallone?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 17, 2019, 9:51pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/4 "2019-12-17T21:51:36Z")

</div>

Nope. Why would this be a problem? If your goal is to empty the Text Input on “Enter” press, then both an empty string `""` and `None` values will result in the text of the input being set to the empty string, which means that checking against `None` is impossible. If you need empty string as a possible supplied value, you’ll need to find a different way to go about this.

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 17, 2019, 9:56pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/5 "2019-12-17T21:56:14Z")

</div>

Ok. My fist goal is to pass through the values upon hitting Enter key. I am using the following code, but it doesnt seem to change anything. can yo assist please?

if event.keyCode == event.VK\_ENTER:  
value = event.source.text

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 17, 2019, 10:09pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/6 "2019-12-17T22:09:34Z")

</div>

1. When you’re supplying code snippets, use three of the back-tick character, a new line, then your code, then a new line, then three more of the back-tick character, or use the `</>`button in the reply area to generate a code-block. This allows for formatting your code in a much nicer manner.
2. Why are you using a Key Event? The only reason you should use that is if you ONLY want the value to be read when Enter is pressed, and NOT if the user clicks elsewhere.
3. It’s not clear what “it doesn’t change anything” means, because your code wouldn’t change anything - you’re only storing a value into a variable. When a user presses Enter, what do you want that code to do? Your current example takes the value of the Text Field’s text property and stores it into a variable named `value`, but performs no action.

You might be trying to do this (?):

```auto
if event.keyCode == event.VK_ENTER:
	event.source.parent.getComponent('Label').text = event.source.text
	event.source.text = ''

```

This would allow for supplying an empty string as a value, at the expense of requiring that the Enter key be pressed for the value to be supplied - clicking elsewhere or pressing Tab would leave the Text Field with the typed value without using it.

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 17, 2019, 10:18pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/7 "2019-12-17T22:18:00Z")

</div>

Hi,

What I want is that when I enter a value, lets say “Abc” in the text input box and press Enter, it should be displayed on the display label, and the text input box shall get cleared.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 17, 2019, 10:25pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/8 "2019-12-17T22:25:12Z")

</div>

> [@qasimahtesham](#):
>
> What I want is that when I enter a value, lets say “Abc” in the text input box and press Enter, it should be displayed on the display label, and the text input box shall get cleared.

That's exactly what the code I supplied does.

```auto
if event.keyCode == event.VK_ENTER:
    # set Label text to Text Field value
	event.source.parent.getComponent('Label').text = event.source.text
    # set Text Field to display an empty string
	event.source.text = ''

```

If what I supplied is NOT doing that, then it might be that you have the supplied code in the wrong area. As you supplied your own code which referenced key events I assumed you were using a **keyPressed** Event as your trigger, so I placed my code there (and in hindsight didn't declare that I had moved from the **propertyChange** Event to a **keyPressed** Event).

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 17, 2019, 10:32pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/9 "2019-12-17T22:32:57Z")

</div>

> [@cmallonee](#):
>
> if event.keyCode == event.VK\_ENTER: # set Label text to Text Field value event.source.parent.getComponent('Label').text = event.source.text # set Text Field to display an empty string event.source.text = ''

Hii,

Thank. Now, the Enter key is working fine and values are passing through as they should, just trying to figure out the thing with field getting clear now.

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 17, 2019, 11:06pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/10 "2019-12-17T23:06:08Z")

</div>

I am using the very same logic to clear the text field, but somehow just not happening.

#Working Fine with Entering Value, but no Screen clearance  
if event.keyCode == event.VK\_ENTER:  
\>event.source.parent.getComponent(‘DisplayTag’).text = event.source.text  
\>event.source.text = ‘’

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 17, 2019, 11:56pm UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/11 "2019-12-17T23:56:52Z")

</div>

Could you post a screenshot of your code in the keyPressed Event?

1. Right-click the Text Field and then select “Scripting”.
2. Expand the “key” Event Handler directory and select “keyPressed”.
3. Take a screenshot of this entire dialog.

Could you also post the Window structure from the Project Browser panel?

1. Locate your Vision Window in the Project Browser.
2. Scroll Make sure the Project browser panel is tall enough that you can capture the Text Field AND the Label.
3. Take a screenshot of the Project Browser.
4. Please include the names of the components you’re trying to use (it looks like `DisplayTag` is your Label, but I also would like the Text Field’s name.

Do you receive any error messages or dialogs? If so, these would be better at explaining the issue than I could be.

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 22, 2019, 5:06am UTC](https://forum.inductiveautomation.com/t/input-from-text-area-input-box-etc-upon-pressing-enter-key-and-then-text-getting-cleared/30774/12 "2019-12-22T05:06:57Z")

</div>

I will get back to you soon Cmall, thanks!
