# How to configure a script for a button's onClick event?

**URL:** <https://forum.inductiveautomation.com/t/how-to-configure-a-script-for-a-buttons-onclick-event/101989>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [February 6, 2025, 5:20pm UTC](https://forum.inductiveautomation.com/t/how-to-configure-a-script-for-a-buttons-onclick-event/101989 "2025-02-06T17:20:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Imran\_Husain](https://avatars.discourse-cdn.com/v4/letter/i/54ee81/32.png) [@Imran\_Husain](https://forum.inductiveautomation.com/u/Imran_Husain)\
**Post date:** [February 6, 2025, 5:20pm UTC](https://forum.inductiveautomation.com/t/how-to-configure-a-script-for-a-buttons-onclick-event/101989/1 "2025-02-06T17:20:02Z")

</div>

I have a View with 5 Text Fields where I want the user to input data into. I have a button that I want to trigger a script when it is clicked. I am unsure of how to write this script. This is what I would like the script to do:

Take the data from the 5 text fields and add them to the identically named columns of the table on the same screen.

**Example:**

**Text Field 1**  
Name: Red  
Data Entered: 11  
**Text Field 2**  
Name: Blue  
Data Entered: 13  
**Text Filed 3**  
Name: Green  
Data Entered: 20  
**Text Field 4**  
Name: Yellow  
Data Entered: 18  
**Text Field 5**  
Name: Black  
Data Entered: 14

_ **Clicks Button** _

**Table**  
**Columns**  
Red\_\_\_Blue\_\_\_Green\_\_\_Yellow\_\_\_Black  
**11** \_\_ 13\_\_\_\_\_\_20\_\_\_\_\_\_18\_\_\_\_\_\_14

Now I know this could just be easier if I make the table editable have the user type in the values directly. However, my next step would be to connect the table to my SQL DB and have the data be sent to a SQL table. I am then going to add a feature to query the SQL DB to show all existing records in the table within my View and have users be able to edit/delete records if needed.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![ryan.perretta](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.perretta/32/75110_2.png) [@ryan.perretta](https://forum.inductiveautomation.com/u/ryan.perretta)\
**Post date:** [February 6, 2025, 5:54pm UTC](https://forum.inductiveautomation.com/t/how-to-configure-a-script-for-a-buttons-onclick-event/101989/2 "2025-02-06T17:54:44Z")

</div>

You'll have to set up an `onActionPerformed` or `onClick` event on the button that triggers a script that gets each Text Field's value using the button component's [object traversal functions](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods#object-traversal) OR use the browse properties tool (at the top right of the scripting area). You'd probably want to perform some input validation here as well.

Once you have all that, you can append the row to the table's `data` property as a dictionary having the column names as keys and the inputs as the values (where the table's `data` property is a list of dictionaries).

I see you are newer to the forum. Don't know if you are new to Ignition, but I'd recommend watching some of the [Inductive University courses](https://inductiveuniversity.com/) to familiarize yourself with the capabilities of Ignition. It covers topics like this and more.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [February 6, 2025, 6:15pm UTC](https://forum.inductiveautomation.com/t/how-to-configure-a-script-for-a-buttons-onclick-event/101989/3 "2025-02-06T18:15:37Z")

</div>

> [@ryan.perretta](#):
>
> gets each Text Field's value using the button component's [object traversal functions](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods#object-traversal)

I recommend first binding the text field values to custom properties of the view so that you can reference those instead of the input values themselves. That way if you ever need to reorganize/rename those components, you can do so without having to update all the references to their values, which become as simple as `self.view.custom.[customProp]` instead of a bunch of `getParent()/getChild()/getSibling()` traversal. It also makes debugging easier when you can see all of the values sitting side-by-side at the view level.
