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,165
  • 21
  • 93
  • 185

2 Answers2

3

There are the following events

onkeydown

onkeyup

onkeypress

John Hartsock
  • 82,242
  • 22
  • 125
  • 144
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,433
  • 5
  • 24
  • 45
Bonshington
  • 3,772
  • 2
  • 24
  • 20