Execute a JavaScript when a user changes the content of an input field:
Modify the text in the input field, then click outside the field to fire the onchange event.
<!DOCTYPE html> <html> <body> Enter some text: //ww w.j av a 2s .c o m <input type="text" name="txt" value="Hello" onchange="myFunction(this.value)"> <p id="demo"></p> <script> function myFunction(val) { document.getElementById("demo").innerHTML = "The input value has changed. The new value is: " + val; } </script> </body> </html>