Solved

capturing the last keystroke

Posted on 2004-09-16
2
555 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

729 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