cancelling events, NN vs IE

P

Paul THompson

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.type == 'text' ||
docContents.type == 'textarea' ||
docContents.type == 'radio' ||
docContents.type == 'checkbox' ||
docContents.type == 'select-one' ||
docContents.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.nodeName == "DIV") {
divhold=docContents.id;divcnt++;
}
if (docContents.type == 'text' ||
docContents.type == 'textarea' ||
docContents.type == 'radio' ||
docContents.type == 'checkbox' ||
docContents.type == 'select-one' ||
docContents.type == 'select') {
dCitems[xmaxv]=i;
dCnames[xmaxv]=docContents.name;
dCtypes[xmaxv]=docContents.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:"+dCnames[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) {
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+",dCnames:"+dCnames+",dCtypes:"+dCtypes);
}
}
 
M

Martin Honnen

Paul said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top