Solved

capturing the last keystroke

Posted on 2004-09-16
2
538 Views
Last Modified: 2012-05-05
I'd like to be able to capture the immediately preceeding keystroke and use it with an onClick (or some appropriate event) with an INPUT statement to keep the user from proceeding if the last character wasn't an ENTER(13).

Thanks

0
Comment
Question by:tmccar10
2 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 75 total points
ID: 12074120
Hi...

Here's a quick HTML file that you can use to see the functionality you're requesting...

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>

<script language=JavaScript>

var myKeyCode = '';

function doKeyDown (e) {
    myKeyCode = e.keyCode;
}

function testForEnter() {
      if (myKeyCode != 13) {
            alert("Last keystroke was NOT enter!");
      } else {
            alert("Last keystroke was enter!");
      }
}

</SCRIPT>
</head>

<body onKeyDown="return doKeyDown(event);">
<form name="my_form">
<input type="button" name="the_button" value="test for enter" onclick="testForEnter();">
</form>
</body>
</html>

HTH!
0
 

Author Comment

by:tmccar10
ID: 12074973
EXCELLENT!!!!!!!!!!!!!!!

Virtually no (well, very little) tweeking and works exactly as I need it.

(On of the best 75 points I've spent)

Thanks!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now