Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > cancelling events, NN vs IE

Reply
Thread Tools

cancelling events, NN vs IE

 
 
Paul THompson
Guest
Posts: n/a
 
      12-07-2003
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]);
}
}
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-08-2003


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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cancelling session when user closes browser window... Charlie@NISH ASP .Net 3 08-30-2005 08:00 PM
"Cancelling" more that one message at a time Perk Firefox 1 01-01-2005 05:38 AM
Cancelling the events Vik ASP .Net 1 04-06-2004 08:43 PM
Cancelling a HTTP data post del ASP .Net 1 11-09-2003 07:56 PM
Re: cancelling a postback on a button with javascript Bob ASP .Net 4 07-22-2003 07:10 PM



Advertisments