2

i need to be able to able to detect when any character is entered into a textbox in Javascript, and clear another corresponding textbox. I have used the onfocus method for this but when tabbing between textboxes to get to submit, it removes the data and I don't want it to.

What methods are there I can use to trigger a JS event when a textbox is entered into?

Chris
  • 7,415
  • 21
  • 98
  • 190

2 Answers2

3

There are the following events

onkeydown

onkeyup

onkeypress

John Hartsock
  • 85,422
  • 23
  • 131
  • 146
0

If you use jQuery:

$("#myTextbox").keypress()
$("#myTextbox").keyup()
$("#myTextbox").keydown()

and if you want to find out which key was pressed, try:

$("#myTextbox").keydown(function(e){ alert(e.which); });

if you're not using e.which, you're gonna have cross-browser problems.

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Bonshington
  • 3,970
  • 2
  • 25
  • 20