I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in English (US).

The onchange property of the GlobalEventHandlers mixin is the EventHandler for processing change events.

Syntax

element.onchange = handlerFunction;
var handlerFunction = element.onchange;

handlerFunction must be either null or a JavaScript function specifying the handler for the event.

Example

This example logs the number of characters in an <input> element, every time you change its contents.

HTML

<input type="text" placeholder="Type something here, then click outside of the field." size="50">
<p id="log"></p>

JavaScript

let input = document.querySelector('input');
let log = document.getElementById('log');

input.onchange = inputChange;

function inputChange(e) {
  log.textContent = `The field's value is
      ${e.target.value.length} character(s) long.`;
}

Result

Specification

Specification Status Comment
HTML Living Standard
The definition of 'onchange' in that specification.
Living Standard  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

Tag del documento e collaboratori

Hanno collaborato alla realizzazione di questa pagina: mfluehr, fscholz, erikadoyle, jpmedley, cvrebert, groovecoder, teoli, kosvrouvas, kscarfone, Nickolay, ethertank, Sheppy, ziyunfei, Mgjbot, Tmetro
Ultima modifica di: mfluehr,