Disparar evento manualmente

by Luis Martin

HTML

<input type="text" onChange="alert('hi')" id="prueba">

<input type="button" value="cambiar" onclick="cambiar()">

JavaScript

function cambiar() {
  var texto = document.getElementById("prueba")
  texto.value = "hola";
  if (typeof texto.onchange === "function") {
    texto.onchange();
  }


}