473,390 Members | 936 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,390 software developers and data experts.

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="javascript">
<!--
tab = 0;
if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}
function setTabs (childObject) {
for (j=0;j<childObject.childNodes.length;j++) {
try {
childObject.childNodes[j].tabIndex = tab;
tab++;
if
(childObject.childNodes[j].childnodes.length > 0)
setTabs(childObject.childNodes[j]); //should not have to check length before
recurse
}
catch (e) {
}
}
}
function onLoadEvent() {
setTabs(document.getElementById('divTopHeader'));
setTabs(document.getElementById('divTopMenu'));
setTabs(document.getElementById('divTopBody'));
setTabs(document.getElementById('divTopFooter'));
}
//-->
</script>

Jul 23 '05 #1
8 9677
>From: David McDivitt <x1*********@del-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="javascript">
<!--
tab = 0;
if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}
function setTabs (childObject) {
for (j=0;j<childObject.childNodes.length;j++) {
try {
childObject.childNodes[j].tabIndex = tab;
tab++;
if
(childObject.childNodes[j].childnodes.length > 0)
setTabs(childObject.childNodes[j]); //should not have to check length before
recurse
}
catch (e) {
}
}
}
function onLoadEvent() {
setTabs(document.getElementById('divTopHeader'));
setTabs(document.getElementById('divTopMenu'));
setTabs(document.getElementById('divTopBody'));
setTabs(document.getElementById('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.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}
function setTabs (node) {
for (j=0;j<node.childNodes.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.childNodes.length>0) { //check not
necessary but faster
recurse.push(j);
recurse.push(node);
setTabs(child);
node = recurse.pop();
j = recurse.pop();
}
}
}
}
function onLoadEvent() {
setTabs(document.getElementById('divTopHeader'));
setTabs(document.getElementById('divTopMenu'));
setTabs(document.getElementById('divTopBody'));
setTabs(document.getElementById('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*********@del-yahoo.com> <snip> function setTabs (childObject) {
for (j=0;j<childObject.childNodes.length;j++) {
try {
childObject.childNodes[j].tabIndex = tab;
tab++;
if
(childObject.childNodes[j].childnodes.length > 0)
setTabs(childObject.childNodes[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*********@del-yahoo.com><snip> function setTabs (childObject) {
for (j=0;j<childObject.childNodes.length;j++) {
try {
childObject.childNodes[j].tabIndex = tab;
tab++;
if
(childObject.childNodes[j].childnodes.length > 0)
setTabs(childObject.childNodes[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*********@del-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*********@del-yahoo.com>

<snip>
function setTabs (childObject) {
for (j=0;j<childObject.childNodes.length;j++) {
try {
childObject.childNodes[j].tabIndex = tab;
tab++;
if
(childObject.childNodes[j].childnodes.length > 0)
setTabs(childObject.childNodes[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*********@del-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*********@del-yahoo.com>

<snip>
function setTabs (childObject) {
for (j=0;j<childObject.childNodes.length;j++) {
try {
childObject.childNodes[j].tabIndex = tab;
tab++;
if
(childObject.childNodes[j].childnodes.length > 0)
setTabs(childObject.childNodes[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*********@del-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/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #8
>From: "Dietmar Meier" <us***************@innoline-systemtechnik.de>
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
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...
1
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. ...
1
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,...
18
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...
6
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
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...
5
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...
1
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"...
7
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.