?
Solved

capturing the last keystroke

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

764 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