473,408 Members | 1,762 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,408 software developers and data experts.

cancelling events, NN vs IE

I have been working for some time to 1) detect tab and shift tab
events 2) control the focus on the basis of these events. I have
found that I can do this, but continue to have nagging problems.

One of the main problems at this point lies in cancelling the event.
I have found that the TAB fires the onkeypress in NN, but not in IE.
I can cancel the onkeypress fine in NN. The TAB fires the onkeydown
in IE and can be cancelled in IE. This all works fine. I cancel
events in both cases by

return false;

However, I have one problem. In NN, when focus is on a select object,
onkeypress will not fire when TAB is pressed. Rather, only onkeydown
fires.

I cannot cancel onkeydown in NN. I would use onkeydown routinely, but
have not determined how to cancel it in NN. In IE, it cancels fine.

Can anyone tell me if there is some secret to cancelling onkeydown in
NN? Is this one of those bubble-up deals?

Code details:

BROWSER DETECTION:

function getBrowser() {
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
bType="None";
if (bName == "Netscape" && bVer >= 5) {bType="nn5";}
else if (bName == "Netscape" && bVer >= 4) {bType="nn4";}
else if (bName == "Netscape" && bVer >= 3) {bType= "nn3";}
else if (bName == "Netscape" && bVer == 2) {bType= "nn2";}
else if (bName.indexOf('Microsoft') >= 0 && bVer >= 4) {bType=
"ie4";}
else if (bName.indexOf('Microsoft') >= 0 && bVer >= 2) {bType=
"ie3";}
return bType;
}

DOCUMENT DECOMPOSITION:

function fixstart(f) {
zmaxv=0;xmaxv=0;setstart=0;
docContents = document.getElementsByTagName("*");
for (var i=0; i < docContents.length; i++) {
if (docContents[i].type == 'text' ||
docContents[i].type == 'textarea' ||
docContents[i].type == 'radio' ||
docContents[i].type == 'checkbox' ||
docContents[i].type == 'select-one' ||
docContents[i].type == 'select') {zmaxv++;}
}
dCitems=new Array(zmaxv);dCnames=new Array(zmaxv);
dCtypes=new Array(zmaxv);dCdivs=new Array(zmaxv);
var divhold="null";
divcnt=0
for (var i=0; i < docContents.length; i++) {
if (docContents[i].nodeName == "DIV") {
divhold=docContents[i].id;divcnt++;
}
if (docContents[i].type == 'text' ||
docContents[i].type == 'textarea' ||
docContents[i].type == 'radio' ||
docContents[i].type == 'checkbox' ||
docContents[i].type == 'select-one' ||
docContents[i].type == 'select') {
dCitems[xmaxv]=i;
dCnames[xmaxv]=docContents[i].name;
dCtypes[xmaxv]=docContents[i].type;
dCdivs[xmaxv]=divhold;
xmaxv++;
}
}
}

GENERAL LOGIC:

The overall process is controlled using:

<BODY onkeypress="return nclkH(event,document.rexform,1);"
onkeydown="return nclkH(event,document.rexform,2);return false;"
onkeyup="alert("onkeyup");return false;">

OBJECT IDENTIFICATION:

onfocus="iam='_object';" name="_object"

so that each object is self-identified as focus is established.

OVERALL PROCESS:

function nclkH(eventObject,myForm,typeBrowser) {
if (setstart) {fixstart(eventObject);}
if (bType == "ie3" || bType == "ie4") {prx=0;}
prx=0;
var curpos=findItem(iam);
var spcKey=eventObject.keyCode;var shfKey=eventObject.shiftKey;var
ok;
var iType=dCtypes[curpos];
if (prx) {
alert("typeBrowser:"+typeBrowser+",iam:"+iam); }
if ((typeBrowser == 1 && iType != "select" &&
iType != "select-one" &&
(bType == "nn5" || bType == "nn4" ||
bType == "nn3" || bType == "nn2")) ||
(typeBrowser == 2 &&
(bType == "ie3" || bType == "ie4" ||
iType == "select" || iType == "select-one"))) {
if (prx) {
alert("iam:"+iam+",curpos:"+curpos+",dCnames:"+dCn ames[curpos])
}
if (spcKey == 9) {
ok=1;
oldpos=curpos;
for (i=curpos; ok;) {
if ((iType == "select-one" || iType == "select") &&
(bType == "nn5")) {
if (shfKey) {curpos--;curpos--}
else {}
}
else {
if (shfKey) {curpos--}
else {curpos++}
}
if (curpos < 0) {curpos=0;}
if (curpos >= zmaxv) {curpos=zmaxv-1;}
ok=0;
}
if (prx) {
alert("curpos:"+curpos+",dCnames:"+dCnames[curpos])
}
if (divcnt > 0) {
if (dCdivs[curpos] != "null") {sDv(dCdivs[curpos])}
showVis()
}
docContents[dCitems[curpos]].focus();
eventObject.returnValue=false
eventObject.cancelBubble=true
return false;
}
else {
if (dCtypes[curpos] == 'text' || dCtypes[curpos] == 'textarea')
{
var fx=docContents[dCitems[curpos]].value;
var sx=docContents[dCitems[curpos]].size;
var cnx=findItem(nxitm);
fixBlank(docContents[dCitems[curpos]])
if (fx.length >= sx) {
}
}
}
}
}

DETERMINING THE CURRENT LOCATION:

When I detect a TAB, I first find where I am:

function findItem(itmname) {
var radiopos=-1;var curpos=-1;var ok=1;
var nmarr=itmname.split(/\W/);var cntup=0;
if (nmarr[1] != undefined) {cntup=1;}
for (var i=0; i < zmaxv && ok; i++) {
if (nmarr[0] == dCnames[i]) {
curpos=i;
if (cntup) {radiopos++}
}
if ((curpos > 0 && cntup && radiopos == nmarr[1]) ||
(curpos > 0 && !cntup)) {ok=0}
}
return curpos;
}
function showiam(val) {
//alert("Location - iam:"+iam);
}
function showall() {
for (i=0; i < zmaxv; i++) {
alert("dCitems:"+dCitems[i]+",dCnames:"+dCnames[i]+",dCtypes:"+dCtypes[i]);
}
}
Jul 20 '05 #1
1 1852


Paul THompson wrote:
I have been working for some time to 1) detect tab and shift tab
events 2) control the focus on the basis of these events. I have
found that I can do this, but continue to have nagging problems.

One of the main problems at this point lies in cancelling the event.
I have found that the TAB fires the onkeypress in NN, but not in IE.
I can cancel the onkeypress fine in NN. The TAB fires the onkeydown
in IE and can be cancelled in IE. This all works fine. I cancel
events in both cases by

return false;

However, I have one problem. In NN, when focus is on a select object,
onkeypress will not fire when TAB is pressed. Rather, only onkeydown
fires.

I cannot cancel onkeydown in NN. I would use onkeydown routinely, but
have not determined how to cancel it in NN. In IE, it cancels fine.

Can anyone tell me if there is some secret to cancelling onkeydown in
NN? Is this one of those bubble-up deals?


As far as I remember Mozilla/Netscape key event architecture only allows
to cancel keypress events. It is how they implemented it (or were only
able to implement it) and in the absence of key events in DOM Level 2 it
is difficult to argue with them that any specs says different.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

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

Similar topics

8
by: InvisibleDuncan | last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message...
3
by: mgw | last post by:
Hi, I'm trying to cancel the Shift+F3 key combination in Netscape 7.2 from performing the F3 key's default action of opening the Find dialog. I'm unable thus far to prevent the Find dialog from...
5
by: Dave Hammond | last post by:
Hi All, I have a web form which performs certain actions upon moving focus away from a field. However, if the user clicks the top corner 'X' icon to close the window, the onBlur event still...
7
by: Marina | last post by:
Imagine a form with some fields and an OK buttons that saves the information. Each field has validation logic in the Validating event. If the input is not valid, the control's value is replaced...
0
by: Baseman | last post by:
I am trying to find out how to cancel all TreeView events if an exception occurs during any one of the following... MouseDown BeforeSelect AfterSelect DragDrop DragEnter DragOver...
6
by: PromisedOyster | last post by:
Hi How do I cancel an event in a class where that event is setup in another derived class. See example below. Thanks All our winforms are derived from one of our own classes, BaseForm....
1
by: Vik | last post by:
Is it possible to cancel all the events or a specific event programmatically (for example, in a Page_Load event)? In other words, is it possible to stop a page code execution? Thank you.
9
by: pvsundarram | last post by:
hey, i am trying to cancel the keydown event for certain keycodes( for eg:- enter key ).But the cancelling of this event is not happening in firefox. Is there any way to cancel the event in the...
3
by: Oliver Nelson | last post by:
I have MapPoint working in Python, and I'm trying to cancel events on the map, but I can't seem to make that happen. I'm responding to the events successfully in my panel object. My code is like...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.