473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

onKeyDown, getting rid of keys typed

I'm trying to use the onKeyDown event on a text field. I intersept the
keystroke, interpret it and then do certain actions based on certain
keys stuck. If a special key is stuck I replace the value in the text
field and return false. This seems to say "get rid of the key struck - I
handled it instead" for IE but not for Netscape.

I set up a page, http://defaria.com/test.html to demonstrate this. If
you type any character it is simply inserted. If you type a "t",
however, the field is replaced with the current date. In IE this works
just fine. In Netscape I get the current date followed by the "t"
character! Trying to debug this I inserted an alert into the code. The
strange thing is that with the alert Netscape stops appending the "t"!
This is demonstrated by http://defaria.com/test.html under Netscape
(actually I'm using Firefox). The first box, labelled SetToday1, will
pop up an alert box for any key you type. Again if you type "t" the
current date is inserted and "t" is *not* appended to the date inserted.

The second box, labelled SetToday2, will not pop up an alert box but it
functions similarly in that typing a "t" will insert the current date.
However, SetToday2, without the call to alert, will append a "t" to the
date inserted even though false is being returned. This happens only on
Netscape and not on IE. The question is why?

(To view the source use *View: Source*)
--
When something is "new and improved!". Which is it? If it's new, then
there has never been anything before it. If it's an improvement, then
there must have been something before it.

Jul 23 '05 #1
4 1994

"Andrew DeFaria" <An****@DeFaria.com> wrote in message
news:c8***************************@msgid.meganewss ervers.com...
I'm trying to use the onKeyDown event on a text field. I intersept the
keystroke, interpret it and then do certain actions based on certain
keys stuck. If a special key is stuck I replace the value in the text
field and return false. This seems to say "get rid of the key struck - I
handled it instead" for IE but not for Netscape.

I set up a page, http://defaria.com/test.html to demonstrate this. If
you type any character it is simply inserted. If you type a "t",
however, the field is replaced with the current date. In IE this works
just fine. In Netscape I get the current date followed by the "t"
character!


Use the onkeyup event instead; that way the 't' is overwritten by the date
insertion.
--
Stephen Chalmers

Jul 23 '05 #2
"Stephen Chalmers" <sp*********************@ntlworld.com> wrote in message
news:8htoc.100$R3.83@newsfe1-win...

"Andrew DeFaria" <An****@DeFaria.com> wrote in message
news:c8***************************@msgid.meganewss ervers.com...
I'm trying to use the onKeyDown event on a text field. I intersept the
keystroke, interpret it and then do certain actions based on certain
keys stuck. If a special key is stuck I replace the value in the text
field and return false. This seems to say "get rid of the key struck - I
handled it instead" for IE but not for Netscape.

I set up a page, http://defaria.com/test.html to demonstrate this. If
you type any character it is simply inserted. If you type a "t",
however, the field is replaced with the current date. In IE this works
just fine. In Netscape I get the current date followed by the "t"
character!


Use the onkeyup event instead; that way the 't' is overwritten by the date
insertion.


Huh? Use onKeyup event to do what? IOW what do I do in my onKeyup event
handler to get rid of the "t"? Merely set textbox.value to the correct
value?

Besides this won't work for me. Although my example was merely of using "t"
to get the current date inserted, thus probably only struck once, I want to
then allow "+" to advance one day. Well advancing one day is also a single
keystroke but I want to be able to hold down the "+" key to "scroll" forward
in dates. If I am using onKeyup then this would look real odd as many "+"'s
get inserted, in the process scrolling the date out of sight, only to be
"corrected" when the user finally releases the "+" key.
Jul 23 '05 #3

"Andrew DeFaria" <An****@DeFaria.com> wrote in message
news:17*************************@msgid.meganewsser vers.com...
"Stephen Chalmers" <sp*********************@ntlworld.com> wrote in message
news:8htoc.100$R3.83@newsfe1-win...

"Andrew DeFaria" <An****@DeFaria.com> wrote in message
news:c8***************************@msgid.meganewss ervers.com...
I'm trying to use the onKeyDown event on a text field. I intersept the
keystroke, interpret it and then do certain actions based on certain
keys stuck. If a special key is stuck I replace the value in the text
field and return false. This seems to say "get rid of the key struck - I handled it instead" for IE but not for Netscape.

I set up a page, http://defaria.com/test.html to demonstrate this. If
you type any character it is simply inserted. If you type a "t",
however, the field is replaced with the current date. In IE this works
just fine. In Netscape I get the current date followed by the "t"
character!


Use the onkeyup event instead; that way the 't' is overwritten by the date insertion.


Huh? Use onKeyup event to do what? IOW what do I do in my onKeyup event
handler to get rid of the "t"? Merely set textbox.value to the correct
value?


My response to the problem you mentioned originally meant that if you
trigger your setToday#
functions with onkeyup instead, the 't' appears only momentarily before
being overwritten by
the date. I tried it on your code under Mozilla and it worked.
If now you say you want to do other things with keystrokes, then that's
another matter.
I suggest you look into the use of arrow keys.

--
Jul 23 '05 #4
Stephen Chalmers wrote:
My response to the problem you mentioned originally meant that if you
trigger your setToday# functions with onkeyup instead, the 't' appears
only momentarily before being overwritten by the date. I tried it on
your code under Mozilla and it worked.
As I said, that won't work if you want the action to happen on the
downstroke and/or you want the action to be repeated. Using onKeyUp
would require that the user repetitively strike the key each time in
order to generate a KeyUp event.
If now you say you want to do other things with keystrokes, then
that's another matter. I suggest you look into the use of arrow keys.


Of course I want to do other things! I just broke the problem down to
simplify it here. What I'm hoping to eventually do is emulate the
behavior in Quicken where "t" goes to today and "+" increases the date
and "-" decreases it.

I've improved my test. It now responds to "t" and +/- properly. I had to
implement a onKeyUp event to fix up the date by removing the +/- after
the user releases the key. But under Netscape it just looks, well,
unprofessional! What is the defined behavior supposed to be when the
function returns false? IE takes it as "forget that character". Netscape
doesn't. And the onKeyUp that fixes the date is a hack at best.
--
Ever stop to think, and forget to start again?
Jul 23 '05 #5

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

Similar topics

6
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...
3
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>
4
by: Tony | last post by:
I'm having trouble getting Opera to recognize a repeating key event - I was wondering if anyone had experience with this. Basically, I am trying to move a <div> based on the arrow keys that are...
0
by: bj | last post by:
Hello Recently i've found very interesting problem i made new class derived from UserControl and i need to process arrow keys movments but OnKeyDown method seems to all keys besides arrow keys...
4
by: Udi | last post by:
Hi All, MyRichEdit is derived from RichTextBox. I'm overriding OnKeyDown. I'm trying to handle the TAB key but without printing it in the edit box: protected override bool IsInputKey(Keys...
0
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...
2
by: ra88it | last post by:
I'm working on some javascript games, and I encountered what appears to be a bug specific to Firefox on Linux (I'm using several recent versions of Ubuntu). I'd love to get some help verifying...
3
by: gjain12 | last post by:
Hi all, I am using the following code to disable the ctrl+a/c/v/x keys. <html> <head> <script language="JavaScript" type="text/javascript"> function disableCtrlKeyCombination(e) { //list...
8
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.