?
Solved

capturing the last keystroke

Posted on 2004-09-16
2
Medium Priority
?
559 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 300 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

864 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