Hi,
In Javascript, the simple way to check user input is to get the keycode.
But for cross browser, its seems we need to have two different keycodes
for the same key.
There is a web page for get keycode vs event types. http://www.w3.org/2002/09/tests/keys-cancel2.html
Try open this URL in IE and FX, input + this character. For the keydown
event, in IE is 187 but in FX is 61.
Do you have any idea without create two sets for different browsers? For
example, I created a allowed keycode array for validation, but if the
keycode for keydown event is browser relative, it is very bad and take
time to create different set for validation.
Thanks,
Ming 6 14213 mi*********@gma il.com said the following on 12/3/2006 6:17 AM:
Hi,
In Javascript, the simple way to check user input is to get the keycode.
No, it isn't. You use the onchange event handler and validate it after
it gets changed, not while the user types.
P.S. How would you check my input if I paste it into the input using
<shift><enter >?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Randy Webb <Hi************ @aol.comwrote:
No, it isn't. You use the onchange event handler and validate it after
it gets changed, not while the user types.
P.S. How would you check my input if I paste it into the input using
<shift><enter >?
ok, there are two ways for user input validation. One is invoke validation
function on keydown and one validation rule is for check characters for
this field. For your question, this is second validation. In my deisgn, to
check the user input while user press keyboard, for the copy and paste, use
another function to do it. This one is triggered by on paste (IE) and on
input (FX).
Everything is working fine except the capture keycode for keydown event in
different browsers.
Cheers,
Ming mi*********@gma il.com a écrit :
There is a web page for get keycode vs event types.
http://www.w3.org/2002/09/tests/keys-cancel2.html
Try open this URL in IE and FX, input + this character. For the keydown
event, in IE is 187 but in FX is 61.
Tried this page and with FF on my Mac
[+] on numeric keypad I get : keyDown = keyUp = 107
Shift -ShiftKey ok and KeyDown = 16
Shift + key [+ =] --ShiftKey ok and keyDown = keyUp = 0
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>key code alert</title>
<script type="text/javascript">
function KeyCheck(evt) {
evt = (evt) ? evt : ((event) ? event : null);
var evver = (evt.target) ? evt.target : ((evt.srcElemen t)
?evt.srcElement : null );
var keynumber = evt.keyCode;
if(keynumber){
alert(keynumber );
}
}
</script>
</head>
<body onkeyup = "KeyCheck(event )">
Type in the form area below to view alerts as to which key is
pressed;<br/>
for cross browser compliance, this code detects the onKeyUp event.<br/>
<form>
<textarea rows="8" cols="30" style="backgrou nd-color:cyan; color:navy;
border:3px red ridge;"></textarea>
</form>
</body>
</html> mi*********@gma il.com wrote:
In Javascript, the simple way to check user input is to get the
keycode. But for cross browser, its seems we need to have two
different keycodes for the same key.
Capturing keypresses is tricky, and I've yet to find a good solution that
normalizes the browser and event differences so you can just get the text of
the key pressed. It's on my to-do list, but I can't believe someone has
created such a beast yet. It doesn't exist in any of the common js
"frameworks " that I've seen, nor in any stand-alonw routines. If anyone
knows of a good solution, I'd love to see it.
--
Matt Kruse http://www.JavascriptToolbox.com http://www.AjaxToolbox.com
Matt Kruse <ne********@mat tkruse.comwrote :
Capturing keypresses is tricky, and I've yet to find a good solution that
normalizes the browser and event differences so you can just get the text of
the key pressed. It's on my to-do list, but I can't believe someone has
created such a beast yet. It doesn't exist in any of the common js
"frameworks " that I've seen, nor in any stand-alonw routines. If anyone
knows of a good solution, I'd love to see it.
As you mentioned, to normalizes it for cross browser is the only
solutoin. Just a little bit worry is the same browser but different
behavior between different platform.
Cheers,
--
Ming-Chin Chen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: oeyvind toft |
last post by:
How do I capture the ctrl keypress?
Is it possible for js to intercept the ctrl-n combination and prevent
the creation of a new IE window??
(Have 3 huge books on js and none of them mention this subject)
Oeyvind
|
by: Julia Briggs |
last post by:
Are there any gotchas using if (event.keyCode==8)? I understand that
to represent backspace, but it doesn't work. I am running Windows XP,
using a typical keyboard - but no luck in detecting backspaces. Anyone
have experiences with this?
|
by: Thomas Christensen |
last post by:
I'm trying to figure out what key the user pressed using a Danish
keyboard layout. charCodeAt returns the correct number, but
event.keyCode returns a wrong number, when using one of the keys that
are different on a Danish keyboard layout. "-" returns 45 and 189
respectively. Etc. (The input-field in the sample code below displays
the right character).
I've tried setting the lang-parameter to 'da', but it doesn't make a
difference.
|
by: kids_pro |
last post by:
Hi there,
I want to capture the last key press in a textBox.
So I decided to use KeyDown event and from the KeyEventArgs I read the
e.KeyCode
But when I type small letter the e.KeyCode always return upper case letter.
Is there any configuration so that I can capture the correct letter case?
Also in Vb I can change KeyAscii to another value. How can I do that in C#?
Regards,
|
by: melanieab |
last post by:
Hi,
Just checking to see if there's anything I can possibly do to allow for the
recognition of the Tab key being pressed. On the KeyDown event I've tried:
if (e.KeyCode == Keys.Tab),
if (Control.ModifierKeys == Keys.Tab),
checked for it by
MessageBox.Show((e.KeyValue).ToString()); (it responded to every key I tried
except for Tab)),
| |
by: strah |
last post by:
I am trying to detect when a user uses Tab key while with the KeyDown
event of the combobox. It seems to work fine with all the Keys (Enter,
T, ...) but not with the Tab key (e.KeyCode = Keys.Tab). Anyone
experienced similar problems? Any solutions, workarounds? thanks
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Tab Then
|
by: Alberto |
last post by:
Could you tell me witch is the difference between keycode, keyvalue and
keydata in a keydown event?
keyvalue is always the ascii code?
thank you
|
by: Pugi! |
last post by:
I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using
Javascript & DOM'.
function aKeyWasPressed(e) {
if (window.event) {
var key = window.event.keyCode;
} else {
var key = e.keyCode;
}
alert('You pressed the key: ' + String.fromCharCode(key));
|
by: WilliamRLinden |
last post by:
Hi world! we are pretty new to JavaScript and have been
struggling for now 2 days on this problem ... We would
appreciate mercy if anyone can give us some.
Basically we are trying to simulate the tab key when the
down arrow key is pressed. (we know there are other way
to control focus flow but we use a lot of dynamic jsp fields,
that will make the flow control a nightmare, we just want
basic tabbing from the arrow key)
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |