Solved

capturing the last keystroke

Posted on 2004-09-16
2
551 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Scroll To Top 5 40
How to resize a div in html 3 39
multiple selects 23 49
Possible propagation problem 1 25
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

830 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