473,795 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange onkeydown behaviour (works with alert, NOT without)

Hi,

This is a strange issue I'v been staring at for half a day now.
It concerns catching keys via the onkeydown handler.

In IE5+ it works fine but in Moz 1.6 (& Firebird 0.7+) it behaves most
peculiar. The 'offensive' code is included below.

The weird thing lies in the alert box preceded by // **.
* function textboxReplaceS elect *
If the alert is active it works perfect. No key duplication in the textbox
on the screen.
insert the comment ()i.e. take out the alert) and one gets two characters
instead of one.
It almost looks like something 'shoots through' because (to make things
worse) the last alert shows me a singular entry as well.

To test the code just use the following

TIA
Fermin DCG

<html>
<head>
<script>
var isIE = navigator.userA gent.indexOf('M SIE') > 1;
var isMoz = navigator.userA gent.indexOf('M ozilla/5.') == 0;var _character;
var _keyCode;
var _charCode;

// decipher key down codes
function showDown(oTextb ox, evt) {
_keyCode = _charCode = _character = null;
evt = (evt) ? evt : ((event) ? event : null);

if (evt) {
_keyCode = evt.keyCode;
if (evt.charCode) _charCode = evt.charCode;
else _charCode = (isIE) ? _keyCode : ((_charCode) ? _charCode : _keyCode);
_character = String.fromChar Code(_charCode) .toLowerCase();
}
textboxReplaceS elect(oTextbox, _character);
return false;
}
/** THE OFFENSIVE CODE
* Replace the currently selected text with some other text
* F.e.: when a <x> is pressed in an empty textbox it should come out with
1 x only on the screen.
* @param oTextbox = the textbox to act on
* @param sText = the text to insert
*/
function textboxReplaceS elect (oTextbox, sText) {
if (isIE) {
var oRange = document["selection"].createRange();
oRange.text = sText;
oRange.collapse (true);
oRange.select() ;
} else if (isMoz) { // THIS DOES NOT WORK AS EXPECTED
var oldText = oTextbox["value"];
var iSelEnd = oTextbox["selectionE nd"];
var iStart = oTextbox["selectionStart "];
oTextbox.value = "";
// ** UNCOMMENT AND THE CODE WORKS
//alert("1.textbo xReplaceSelect: :"+oldText+" - "+sText+" - "+
oTextbox.value) ;
//oTextbox.value = oTextbox.value. substring(0, iStart) + sText +
oTextbox.value. substring(oText box.selectionEn d, oTextbox.value. length);
oTextbox.value = oldText.substri ng(0, iStart) + sText +
oldText.substri ng(iSelEnd, oldText.length) ;
//alert("2.textbo xReplaceSelect: :"+oTextbox.val ue+" - "+sText);
oTextbox.setSel ectionRange(iSt art + sText.length, iStart + sText.length);
}

oTextbox.focus( );
alert("exit.tex tboxReplaceSele ct::"+oTextbox. value+" - "+sText);
}

</script>
</head>
<body>
<input type="text" value="" id="txtSearch" onkeydown="retu rn showDown(this,
event);" />
</body>
</html>
Jul 20 '05
11 1874
Janwillem Borleffs wrote:
Janwillem Borleffs wrote:
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> schreef in bericht
news:3F******** ******@PointedE ars.de...

Your UA (Outlook Express) is borken which makes your postings hardly
leagible. Please use OE Quotefix, a similar tool or simply a working ^^
Sorry, my bad. s/ea/e/
UA.


[...]


Is this better?


Yes, it is.
F'up2 poster

PointedEars
Jul 20 '05 #11
JRS: In article <3f************ *********@news. wanadoo.nl>, seen in
news:comp.lang. javascript, Janwillem Borleffs <jw@jwscripts.c om> posted
at Sat, 27 Dec 2003 14:44:03 :-

"Thomas 'PointedEars' Lahn" <Po*********@we b.de> schreef in bericht
news:3F******* *******@Pointed Ears.de...

Your UA (Outlook Express) is borken which makes your postings hardly
leagible. Please use OE Quotefix, a similar tool or simply a working UA.


What is broken about my UA??????????


Ignore him; he wants to be a dictator. The concept is discredited.

--
© John Stockton, Surrey, UK. ??*@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jul 20 '05 #12

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

Similar topics

6
3913
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...
2
1976
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which catches all exceptions that have not be handled at a higher level. The catch block cleans up and...
8
1287
by: Raoul Borges | last post by:
Hi! I have a simple IF/ELSE IF/ELSE block, and it won't work as I hoped: K_IMG_RED(), K_IMG_BLUE() are function that returns either 1 or 2 (the numbers). I use them as constants. ================================ if( p_iImg == K_IMG_RED() ) /* LINE 0*/
4
10026
by: KublaiKhan | last post by:
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>Reading Keystrokes</title> <script language="JavaScript"> window.onkeyDown = keyHit;
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>
2
5959
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...
1
1542
by: Joe | last post by:
Hi folks, Been looking at this for the day so any ideas would be appreciated. Here's the scenario, bear with me - it looks more complicated than it is :) I have a page templating system that inherits from the page class and adds a mixture of usercontrols and literals when requested. One of the usercontrols is a menu that expands on being clicked using DHTML. What I'm trying to do is to persist the expanded menu to other pages or
8
4274
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
2
1265
by: Roman | last post by:
Hi, I have small problem. What is wrong within this script ? It works on my PC (IE6, IE7, FF) but doesn't work on other PCs with the same configuration ? Any idea ? function addPointOnTypingDate(field){ var f = document.getElementById(field); f.onkeydown=function(e){ var e=window.event || e if (e.keyCode != 8 && e.keyCode != 46) {
0
9672
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
10437
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
10001
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
9042
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
6780
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
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
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...

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.