473,811 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onkeydown

I am trying to figure out what values are returned when keys are
pressed in Mozilla & IE. Here's the code I'm using. There are no
alerts in either browser. Any clues would be greatly appreciated.
Thanks. KK

<html>
<head><title>Re ading Keystrokes</title>

<script language="JavaS cript">
window.onkeyDow n = keyHit;
function keyHit(evt) {
if (evt && evt.which) { //NS
thisKey = evt.which;
}
else if(window.event && window.event.ke yCode) { //IE
thisKey=window. event.keyCode;
}
alert(thisKey)
}
</script>
</head><body></body></html>
Jul 23 '05 #1
4 10027
The method I used to get your script to work is this. First I put the
'onKeyDown' handler in the <body> tag. Second inside the keyHit() function
I made the first line--

var evt = window.event;

--the code works in this format in IE, though I don't know about any cross
browser application.

Do you know anything about how to disable the Backspace Key from
performing the history.back method? I can disable it for text but not for
browsing.

Jul 23 '05 #2
KublaiKhan wrote:
I am trying to figure out what values are returned when keys are
pressed in Mozilla & IE. Here's the code I'm using. There are no
alerts in either browser. Any clues would be greatly appreciated.
Thanks. KK

<html>
<head><title>Re ading Keystrokes</title>

<script language="JavaS cript">
<script type="text/javascript">
window.onkeyDow n = keyHit;
document.onkeyd own = keyHit;
function keyHit(evt) {
if (evt && evt.which) { //NS
thisKey = evt.which;
}
else if(window.event && window.event.ke yCode) { //IE
thisKey=window. event.keyCode;
}
alert(thisKey)
}
function keyHit(evt) {
evt = evt || window.event;
alert(evt.which ? evt.which : evt.keyCode);
}
</script>
</head><body></body></html>


--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

"KublaiKhan " <bi*****@hotmai l.com> wrote in message
news:f0******** *************** ***@posting.goo gle.com...
I am trying to figure out what values are returned when keys are
pressed in Mozilla & IE. Here's the code I'm using. There are no
alerts in either browser. Any clues would be greatly appreciated.
Thanks. KK

<html>
<head><title>Re ading Keystrokes</title>

<script language="JavaS cript">
<script type="text/javascript">
window.onkeyDow n = keyHit;
document.onkeyd own = keyHit;
if you just want general keyboard response use the
onkeypress handler. It handles upper/lower case
numbers and punctuation. Onkeydown requires a solid
understanding of handling key events.
function keyHit(evt) { if (evt && evt.which) { //NS
// you haven't declared thisKey and it will
// be available as a global variable to the rest of
// your script/s !!
var thisKey; // now local variable
thisKey = evt.which; }
else if(window.event && window.event.ke yCode) { //IE
thisKey=window. event.keyCode;
}
alert(thisKey)
}
</script>
</head><body></body></html>


<script type="text/javascript">
document.onkeyp ress = keyHit;

function keyHit(evt) {
var e = evt || window.event;
var thisKey = e.which || e.keyCode;
alert(String.fr omCharCode(this Key));
}
</script>
HTH
Jimbo
Jul 23 '05 #4
"koethler" <ko******@telus .net> wrote in message news:<45******* *************** ********@localh ost.talkaboutpr ogramming.com>. ..
The method I used to get your script to work is this. First I put the
'onKeyDown' handler in the <body> tag. Second inside the keyHit() function
I made the first line--

var evt = window.event;

--the code works in this format in IE, though I don't know about any cross
browser application.

Do you know anything about how to disable the Backspace Key from
performing the history.back method? I can disable it for text but not for
browsing.


I simplified the code on Grant Wagner's advice to:
<html>
<head><title>Re ading Keystrokes</title>

<script type="text/javascript">
document.onkeyd own = keyHit;
function keyHit(evt) {
evt = evt || window.event;
alert(evt.which ? evt.which : evt.keyCode);
}
</script>
</head><body></body></html>

Turns out my original problem was I had document.onkeyD own instead of
document.onkeyd own (lowercase). Now it works fine under Mozilla & IE6.
Thanks folks. I am very new js. With that in mind, I have pages
1,2,3,4. Link on p. 1 takes you p. 2 which checks for cookies & if
false, does a
this.location.h ref="page3.html "
P. 3 first line is
<meta http-equiv=refresh content="0;url= page4.html">
A link in page 4 then takes you to p. 2. Backward navigation from p.2
now takes you to p.1 with pages 3 & 4 erased from history.
Something to think about.

KK
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3917
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and thus do not permit changing the assigned KeyCode. My question is this: How do I change the KeyCode...
3
7409
by: euler | last post by:
why did the keydown event not fire in this simple example? <HTML> <HEAD><title>keydown_div</title> <script type="text/javascript"> function keydown() { alert("keydown"); } </script>
10
9176
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);}, false); }
2
5960
by: Iver Erling Årva | last post by:
I have come across a problem with the onKeyDown event in some of my forms. I'm using onKeyDown in <form> as a standard method to open my help screen system throughout my system, but I have discovered that If I have a <div></div> section somewhere and then load the contents of it from another file using innerHTML after the main window is loaded, the onKeyDown event doesn't trigger any more. I'm using IE6 and the structure is: <body...
5
3786
by: Roger Withnell | last post by:
I'm using the following code to start a function on key down. document.onkeydown = OnKeyDown; function OnKeyDown() { vKeyCode = event.keyCode; ..code... }
0
1147
by: =?Utf-8?B?Q0dX?= | last post by:
I have a .NET 1.1 application which uses several grids of text boxs (in repeaters and datagrids) for entering arrays of time values. I use onkeydown to allow users to navigate through the grids using arrow keys. I'm attempting to upgrade to .NET 2.0, but that particular functionality appears to be broken now. The actual javascript function is quite long and really irrelevant since the problem appears to be with the onkeydown event firing...
0
1197
by: CGW | last post by:
I posted this in a .NET general newsgroup, but then found this group and I think it would be more appropriately posted here. Even though the problem is partially with client side behavior, I'm attempting to deal with it in my VB code behind. Here's my post... I have a .NET 1.1 application which uses several grids of text boxs (in repeaters and datagrids) for entering arrays of time values. I use onkeydown to allow users to navigate...
1
5761
eboyjr14
by: eboyjr14 | last post by:
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere! // ==UserScript== // @name iGoogle Suggest // @namespace Devin Samarin // @description This automatcally selects the top result for your query. // @include *google.com/ig* // ==/UserScript== function makeRequest() {
8
4282
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these raise an event how do I create an handler to catch these raised events. //Tony
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.