Look into "bind". These slides will help: http://ejohn.org/apps/learn/