# CustomElement with Input - How to get value from Input element?

**URL:** <https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923>\
**Category:** Ask the community\
**Tags:** wix-editor, code\
**Created:** [April 6, 2024, 10:55pm UTC](https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923 "2024-04-06T22:55:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1981](https://avatars.discourse-cdn.com/v4/letter/u/71c47a/32.png) [@user1981](https://forum.wixstudio.com/u/user1981)\
**Post date:** [April 6, 2024, 10:55pm UTC](https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923/1 "2024-04-06T22:55:09Z")

</div>

I am using Wix website editor to create a CustomElement that has an Input element within it. I have nearly everything working - except, I cannot figure out how to get the Input element’s value from the page code. I can set the value easily using .setAttribute(). But…there is no .getAttribute() - so how can I get the value from the CustomElement?

I’ve defined getter and setter for the “value” property - and they work fine from “within” the CustomElement.

But I cannot call the getter from the page code…the error is “Property ‘value’ does not exist on type ‘CustomElement’.”

I’ve read through all of the examples Wix has provided - dropdown, helloworld, chart, etc. nothing is leading me down the right path. This should be so simple - I just want to get the value of a text box in my CustomElement.

---

<div class="post-metadata">

**Author:** ![iSamurai](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/isamurai/32/89043_2.png) [@iSamurai](https://forum.wixstudio.com/u/iSamurai)\
**Post date:** [April 6, 2024, 11:06pm UTC](https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923/2 "2024-04-06T23:06:21Z")

</div>

Hi, @user1981

See [Velo Reference \> CustomElement \> on( )](https://www.wix.com/velo/reference/$w/customelement/on)

In your page code you can listen to events dispatched by the Custom Element with the _.on()_ function. And in the Custom Element. your dispatched _event_ will carry a _detail_ property (object) which you can use to send your data to the Page code.

---

<div class="post-metadata">

**Author:** ![user1981](https://avatars.discourse-cdn.com/v4/letter/u/71c47a/32.png) [@user1981](https://forum.wixstudio.com/u/user1981)\
**Post date:** [April 6, 2024, 11:22pm UTC](https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923/3 "2024-04-06T23:22:50Z")

</div>

Thanks for the quick feedback. If my Custom Element had buttons that would trigger events, I can imagine how that would work. In this case, I only have an Input element - there are no events in the Custom Element to trigger.

In the page code, when the form is submitted, I need to grab the value of the Input element from the Custom Element. I can’t imagine how the ‘on’ event would be wired up to work in this case.

---

<div class="post-metadata">

**Author:** ![iSamurai](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/isamurai/32/89043_2.png) [@iSamurai](https://forum.wixstudio.com/u/iSamurai)\
**Post date:** [April 7, 2024, 12:33am UTC](https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923/4 "2024-04-07T00:33:35Z")

</div>

Ok. First thing - we are talking about 2 different events here:

1. We have _oninput_ and _onchange_ which are fired by the \<_input_\> element.
2. _CustomEvent_ which can be fired by the Custom Element and cought by a listener _on()_ in the Page code.

In my response I was talking about the _CustomEvent_.

By what you described I imagine you have a form page and inside a Custom Element there is a \<_input_\> (part of the form data) and the **button** (submit) is in not in the Custom Element.

**In such case:**  
In the Page code prepare to receive a response from the Custom Element which will come wrapped in a event:

```javascript
$w('#customElement').on('responsedataevent', (event) => {
    console.log('Here is your data:', event.detail);
});

```

Still in the Page code, when your submit button is clicked use an attribute to ask Custom Element for data:

```javascript
$w("#myButton").onClick( (event)=>{
    $w('#customElement').setAttribute('sendMeData', 'please');
});

```

In your Custom Element register which attribute must be watched for changes:

```javascript
static get observedAttributes() {
    return ['sendMeData', 'anotherattribute','andother'];
}

```

And what to do when the value of any watched attribute changes. In this case we dispatch an event which carries the input data:

```javascript
attributeChangedCallback( attributeName, oldValue, newValue) {
    if ( attributeName == 'sendMeData' ) {
        let data = 'my input field';
        this.dispatchEvent(new CustomEvent('responsedataevent', { detail: data }));
    }
}

```

---

<div class="post-metadata">

**Author:** ![user1981](https://avatars.discourse-cdn.com/v4/letter/u/71c47a/32.png) [@user1981](https://forum.wixstudio.com/u/user1981)\
**Post date:** [April 7, 2024, 12:17pm UTC](https://forum.wixstudio.com/t/customelement-with-input-how-to-get-value-from-input-element/57923/5 "2024-04-07T12:17:53Z")

</div>

Thank you so much for your thorough reply. Your code samples are super helpful and exactly what I needed to overcome this challenge. THANK YOU!
