Text input onchange event
You probably want to use Drupal behaviors which is a wrapper of sorts for JQuery. With JQuery you can make it so that everytime your textfield gets edited your Javascript code gets executed. Behaviors/JQuery is a big subject and will take time if you're not familiar. You can start here

The Drupal JavaScript API

JQuery tutorials