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.


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

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


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


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


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.`;



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

Browser compatibility

Update compatibility data on GitHub
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


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,