Search.../

onInput( )

Adds an event handler that runs when the input element receives input.

Description

A text input receives an input event when a user changes its input value.

You can retrieve the input element's new value by getting the value from the target property of the Event passed to the handler you set using this function.

Deprecation note: The $w parameter of event handlers is being deprecated. To get a scoped selector for working with elements in repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context). To learn more, see here.

Syntax

function onInput(eventHandler: EventHandler): Element
eventHandler: function EventHandler(event: Event, $w: $w): void

onInput Parameters

NAME
TYPE
DESCRIPTION
eventHandler

EventHandler

The name of the function or the function expression to run when the input element receives input.

Returns

The element on which the event is now registered.

Return Type:

EventHandler Parameters

NAME
TYPE
DESCRIPTION
event

Event

The event that occurred.

$w

$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

Returns

This function does not return anything.

Return Type:

void
Mixed in from:$w.TextInputMixin

Was this helpful?

Get the new input value

Code Example

Copy Code
1$w("#myElement").onInput( (event) => {
2 let newValue = event.target.value; // "newValue"
3} );