$w.ValueMixin

$w.ValueMixin

Adds the value property to elements.

Contents

value Sets or gets an element's value.
onChange( ) Adds an event handler that runs when an input element's value is changed.
value

value

Sets or gets an element's value.

Syntax

get value(): string
set value(value: string): void

Description

To reset the form element's value, set the value property to null or undefined.

Type

String

Examples

Get an element's value

bGV0IG15VmFsdWUgPSAkdygiI215RWxlbWVudCIpLnZhbHVlOyAvLyAiNDIiCg==
let myValue = $w("#myElement").value; // "42"

Set an element's value

JHcoIiNteUVsZW1lbnQiKS52YWx1ZSA9IDQyOwo=
$w("#myElement").value = 42;
onChange( )

onChange( )

Adds an event handler that runs when an input element's value is changed.

function onChange(handler: EventHandler): Element
callback EventHandler(event: Event, $w: Function): void

Description

An element receives a change event when a user changes the value in an input element.

A change event is not triggered when you change an element's value using the element's value property.

Parameters

handler function(event, $w) The name of the function or the function expression to run when the element's value changes.
event Event The event that occurred.
$w $w Deprecated: A selector function. The $w function enables event handlers to work with elements in repeaters and in the global scope.

Return Value

Element The element on which the event is now registered.

Examples

Get the value of the element that was changed

JHcoIiNteUVsZW1lbnQiKS5vbkNoYW5nZSggKGV2ZW50LCAkdykgPT4gewogIGxldCBuZXdWYWx1ZSA9IGV2ZW50LnRhcmdldC52YWx1ZTsgIC8vICJuZXcgdmFsdWUiCn0pOwo=
$w("#myElement").onChange( (event, $w) => {
  let newValue = event.target.value;  // "new value"
});