Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone explain the onkeydown method

Status
Not open for further replies.

Showtime99

Programmer
Sep 24, 2004
14
0
0
US
Hello,

I'm trying to use the onkeydown method to capture keystrokes of users on my webpage. Can anyone give a brief example of how to use this method, as this is foreign to me.

For example, if someone tried to enter: "my favorite color is red", how could I retrieve this with the onkeydown method.

Thanks in advance,
Showtime
 
I wouldn't suggest using the onkeydown event for your example. It would fire on every single keypress. That's useful to trap a certain specific key, such as "enter".

In your case, I think you want the "onchange" event.

When the value of a textbox changes, that event fires.

So an example:

Code:
<html>
<head>
<script type="text/javascript">
function showText(x)
{
  alert(x.value);
}
</script>
<body>
<form>
<input type="text" id="myTextBox" onchange="showText(this);" />
</form>
</body>
</head>
</html>



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top