473,770 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting tab index

I need to set tabs on java generated pages. Pages have four sections:
header, sidebar, body, and footer. The sidebar and body change dynamically.
The tab key must go to anchors, fields, and buttons doing all in the header
first, all in the sidebar second, etc. A base page contains includes for all
the pieces and has the body tag.

I am trying to use code pasted below. Help would be appreciated. Thanks

<script language="javas cript">
<!--
tab = 0;
if(document.all && !document.getEl ementById) {
document.getEle mentById = function(id) {
return document.all[id];
}
}
function setTabs (childObject) {
for (j=0;j<childObj ect.childNodes. length;j++) {
try {
childObject.chi ldNodes[j].tabIndex = tab;
tab++;
if
(childObject.ch ildNodes[j].childnodes.len gth > 0)
setTabs(childOb ject.childNodes[j]); //should not have to check length before
recurse
}
catch (e) {
}
}
}
function onLoadEvent() {
setTabs(documen t.getElementByI d('divTopHeader '));
setTabs(documen t.getElementByI d('divTopMenu') );
setTabs(documen t.getElementByI d('divTopBody') );
setTabs(documen t.getElementByI d('divTopFooter '));
}
//-->
</script>

Jul 23 '05 #1
8 9707
>From: David McDivitt <x1*********@de l-yahoo.com>
Subject: setting tab index
Date: Thu, 07 Apr 2005 13:40:19 -0500

I need to set tabs on java generated pages. Pages have four sections:
header, sidebar, body, and footer. The sidebar and body change dynamically.
The tab key must go to anchors, fields, and buttons doing all in the header
first, all in the sidebar second, etc. A base page contains includes for all
the pieces and has the body tag.

I am trying to use code pasted below. Help would be appreciated. Thanks

<script language="javas cript">
<!--
tab = 0;
if(document.all && !document.getEl ementById) {
document.getEle mentById = function(id) {
return document.all[id];
}
}
function setTabs (childObject) {
for (j=0;j<childObj ect.childNodes. length;j++) {
try {
childObject.chi ldNodes[j].tabIndex = tab;
tab++;
if
(childObject.c hildNodes[j].childnodes.len gth > 0)
setTabs(childO bject.childNode s[j]); //should not have to check length before
recurse
}
catch (e) {
}
}
}
function onLoadEvent() {
setTabs(documen t.getElementByI d('divTopHeader '));
setTabs(documen t.getElementByI d('divTopMenu') );
setTabs(documen t.getElementByI d('divTopBody') );
setTabs(documen t.getElementByI d('divTopFooter '));
}
//-->
</script>


When observing values it seemed stuff was not being saved on the stack when
recursion was done. So in case not, I found the array push and pop
instructions and used them to emulate a stack. The routine works excellent
now. Code is pasted below.

tab = 0;
recurse = new Array();
if(document.all && !document.getEl ementById) {
document.getEle mentById = function(id) {
return document.all[id];
}
}
function setTabs (node) {
for (j=0;j<node.chi ldNodes.length; j++) {
child = node.childNodes[j];
if (child.nodeType ==1) {
if (child.nodeName =='A' ||
child.onClick!= null) {
try {
child.tabIndex = tab;
tab++;
}
catch (e) {
}
}
if (child.childNod es.length>0) { //check not
necessary but faster
recurse.push(j) ;
recurse.push(no de);
setTabs(child);
node = recurse.pop();
j = recurse.pop();
}
}
}
}
function onLoadEvent() {
setTabs(documen t.getElementByI d('divTopHeader '));
setTabs(documen t.getElementByI d('divTopMenu') );
setTabs(documen t.getElementByI d('divTopBody') );
setTabs(documen t.getElementByI d('divTopFooter '));
}

A test will be done for push and pop methods. If not present, setTabs will
exit at top.

Jul 23 '05 #2
David McDivitt wrote:
From: David McDivitt <x1*********@de l-yahoo.com> <snip> function setTabs (childObject) {
for (j=0;j<childObj ect.childNodes. length;j++) {
try {
childObject.chi ldNodes[j].tabIndex = tab;
tab++;
if
(childObject. childNodes[j].childnodes.len gth > 0)
setTabs(child Object.childNod es[j]); //should not have to
check length before recurse
<snip> When observing values it seemed stuff was not being
saved on the stack when recursion was done.

<snip>

"Saved on the stack"? You are using a global variable - j - as a loop
counter in a recursive function. Global variables are not contained by
(restricted to) an execution context so they cannot be expected to be
"saved on the stack" (in so far as javascript's stack of execution
contexts can be regarded as a stack).

Don't waste time, and clock cycles, implementing your own stack, just
follow the general programming axiom that variables should never be
given more scope than they absolutely need and use local variables.
Learning to do so habitually will save you a lot of time and trouble in
the long run.

Richard.
Jul 23 '05 #3
>Subject: Re: setting tab index
Date: Fri, 8 Apr 2005 01:46:43 +0100

David McDivitt wrote:
From: David McDivitt <x1*********@de l-yahoo.com><snip> function setTabs (childObject) {
for (j=0;j<childObj ect.childNodes. length;j++) {
try {
childObject.chi ldNodes[j].tabIndex = tab;
tab++;
if
(childObject .childNodes[j].childnodes.len gth > 0)
setTabs(chil dObject.childNo des[j]); //should not have to
check length before recurse

<snip>
When observing values it seemed stuff was not being
saved on the stack when recursion was done.

<snip>

"Saved on the stack"? You are using a global variable - j - as a loop
counter in a recursive function. Global variables are not contained by
(restricted to) an execution context so they cannot be expected to be
"saved on the stack" (in so far as javascript's stack of execution
contexts can be regarded as a stack).

Don't waste time, and clock cycles, implementing your own stack, just
follow the general programming axiom that variables should never be
given more scope than they absolutely need and use local variables.
Learning to do so habitually will save you a lot of time and trouble in
the long run.

Richard.


The variable j is used only within the setTabs function and is not mentioned
outside that function. How does it therefore have a global scope? Everything
having local scope within the function should go on the stack. That's the
way other languages work. I read articles saying javascript does not put
stuff on the stack very well when doing recursion, so your criticism is not
well founded.

Jul 23 '05 #4
David McDivitt wrote:
You are using a global variable - j - as a loop counter in a
recursive function.
The variable j is used only within the setTabs function and is not
mentioned outside that function. How does it therefore have a global
scope?


The scope is not depending on where and how you use a variable, but
on where and how you declare it. Compare

function ...(...) {
for (j=...; ...; ...) ...
}

with

function ...(...) {
for (var j=...; ...; ...) ...
}

or

function ...(...) {
var j, ...;
for (j=...; ...; ...) ...
}

and read ECMA-262 section 12.2 if you don't see any differene there.

ciao, dhgm
Jul 23 '05 #5
>From: David McDivitt <x1*********@de l-yahoo.com>
Subject: Re: setting tab index
Date: Fri, 08 Apr 2005 08:15:20 -0500
Subject: Re: setting tab index
Date: Fri, 8 Apr 2005 01:46:43 +0100

David McDivitt wrote:
From: David McDivitt <x1*********@de l-yahoo.com>

<snip>
function setTabs (childObject) {
for (j=0;j<childObj ect.childNodes. length;j++) {
try {
childObject.chi ldNodes[j].tabIndex = tab;
tab++;
if
(childObjec t.childNodes[j].childnodes.len gth > 0)
setTabs(chi ldObject.childN odes[j]); //should not have to
check length before recurse

<snip>
When observing values it seemed stuff was not being
saved on the stack when recursion was done.

<snip>

"Saved on the stack"? You are using a global variable - j - as a loop
counter in a recursive function. Global variables are not contained by
(restricted to) an execution context so they cannot be expected to be
"saved on the stack" (in so far as javascript's stack of execution
contexts can be regarded as a stack).

Don't waste time, and clock cycles, implementing your own stack, just
follow the general programming axiom that variables should never be
given more scope than they absolutely need and use local variables.
Learning to do so habitually will save you a lot of time and trouble in
the long run.

Richard.


The variable j is used only within the setTabs function and is not mentioned
outside that function. How does it therefore have a global scope? Everything
having local scope within the function should go on the stack. That's the
way other languages work. I read articles saying javascript does not put
stuff on the stack very well when doing recursion, so your criticism is not
well founded.


Reading Microsoft documentation at
http://msdn.microsoft.com/library/de...sproglobal.asp
it says if the var statement is not used, the variable defaults to global
scope. Your criticism may be correct, Richard. I will try using var instead.
Thanks

Jul 23 '05 #6
>From: David McDivitt <x1*********@de l-yahoo.com>
Subject: Re: setting tab index
Date: Fri, 08 Apr 2005 08:15:20 -0500
Subject: Re: setting tab index
Date: Fri, 8 Apr 2005 01:46:43 +0100

David McDivitt wrote:
From: David McDivitt <x1*********@de l-yahoo.com>

<snip>
function setTabs (childObject) {
for (j=0;j<childObj ect.childNodes. length;j++) {
try {
childObject.chi ldNodes[j].tabIndex = tab;
tab++;
if
(childObjec t.childNodes[j].childnodes.len gth > 0)
setTabs(chi ldObject.childN odes[j]); //should not have to
check length before recurse

<snip>
When observing values it seemed stuff was not being
saved on the stack when recursion was done.

<snip>

"Saved on the stack"? You are using a global variable - j - as a loop
counter in a recursive function. Global variables are not contained by
(restricted to) an execution context so they cannot be expected to be
"saved on the stack" (in so far as javascript's stack of execution
contexts can be regarded as a stack).

Don't waste time, and clock cycles, implementing your own stack, just
follow the general programming axiom that variables should never be
given more scope than they absolutely need and use local variables.
Learning to do so habitually will save you a lot of time and trouble in
the long run.

Richard.


The variable j is used only within the setTabs function and is not mentioned
outside that function. How does it therefore have a global scope? Everything
having local scope within the function should go on the stack. That's the
way other languages work. I read articles saying javascript does not put
stuff on the stack very well when doing recursion, so your criticism is not
well founded.


No, it does not work. Using var does not cause a local variable to go on the
stack if a function is recursed. Critical variables within the function must
be pushed and popped from an array.

Jul 23 '05 #7
David McDivitt <x1*********@de l-yahoo.com> writes:
No, it does not work. Using var does not cause a local variable to
go on the stack if a function is recursed.
Yes it does. A local variable (either one declared with a "var"
declaration inside the body of a function, or a parameter of the
function) is local to one invocation. Recursion works perfectly
fine.

Try:
---
function recurse(n, acc) {
for(var i = 0; i < 2; i++) {
if (n > 0) {
recurse(n-1, acc?[i, acc]:[i]);
} else {
alert([i,acc])
}
}
}
recurse(2);
---
If your description was correct, this call would only alert
0,0,0
and
1,0,0
since "i" is a local (and critical) variable.

Instead it alerts all 8 combinations as it should.
Critical variables within the function must be pushed and popped
from an array.


No. Javascript handles local variables perfectly fine.

If someone doesn't know the rules for when a variable is local, and
uses a global variable in a recursive function, then obviosuly it
doesn't work, but that's due to unfamiliarity with the language,
not a problem with the language itself.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #8
>From: "Dietmar Meier" <us************ ***@innoline-systemtechnik.d e>
Subject: Re: setting tab index
Date: Fri, 8 Apr 2005 15:53:02 +0200

David McDivitt wrote:
You are using a global variable - j - as a loop counter in a
recursive function.

The variable j is used only within the setTabs function and is not
mentioned outside that function. How does it therefore have a global
scope?


The scope is not depending on where and how you use a variable, but
on where and how you declare it. Compare

function ...(...) {
for (j=...; ...; ...) ...
}

with

function ...(...) {
for (var j=...; ...; ...) ...
}

or

function ...(...) {
var j, ...;
for (j=...; ...; ...) ...
}

and read ECMA-262 section 12.2 if you don't see any differene there.

ciao, dhgm

Thanks everyone for the support. I have gotten a good education in
javascript today. Local variables are being put on the stack correctly when
I recurse a function and I have great happiness now.

Jul 23 '05 #9

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

Similar topics

5
21632
by: Soren Vejrum | last post by:
I am working on a web-based html editor using MSIE's designmode and iframes. Everything works just fine, but MSIE changes all my relative "a href" and "img src" links (i.e. "/index.asp") to absolute links (i.e. "http://localhost/index.asp") when I set the iframe's innerHTML. This is bad as the links are supposed to be relative. How can I avoid this? Any solutions/suggestions are much appreciated.
1
11190
by: relaxedrob | last post by:
Howdy All! I am really stuck with this one - I want to completely create a table within JavaScript and insert it into the document, with onMouseOut and onMouseOver handlers in the table rows. Below is a sample of the code I have created. It all works in Netscape 7.1, but in IE 6 it shows the table but the handlers do not run. I can prove the handlers are even there (see the commented out alert command in the code) so why aren't they...
1
6255
by: Erik Hendrix | last post by:
Hi, I have a question here regarding setting the prefetch size. So far we took the rule that for OLTP, prefetchsize = extent size and for DSS prefetchsize = extent size * number. However, especially due to the "Skip Scans" for indexes I started to question this. It looks to me that for reading a index DB2 will or do a synchronous read or he will have to scan the whole index and thus prefetch the data correct? If this is so, then it...
18
18419
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
6
6983
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
0
1581
by: Shravan | last post by:
Hi, I have a extended datagrid, in which I am setting values at a given cell in the grid using grid = val; The grid has NewRow creation set to false But sometimes setting value at a existing row is adding newrow in the grid, which is staying temporarily and when
5
3101
by: john.halet | last post by:
This line of code had been working with out issue, now its throwing errors. In my case I have three items in the ComboBox. If I try to change the selected index it throw the error. Earler in the code I check to see if the combobox has any items, if so then I set it to 0 with out issue. Then a bit later in the code I try to set it to the last server used.
1
6509
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
7
3582
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR Me.cboLocation.Text = ""
0
9432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
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...
1
10008
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
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
8891
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...
1
7420
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.