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

Loop Through Visible Elements

Hey everybody!

I'm in dire need of some help.
I'm trying to loop through all the elements in a form, and determine
whether or not the field is visible. Kinda like this:

var TForm = document.form1;

for (i=0;i<TForm.length;i++)
{
if (TForm.elements[i].style.visibility=="visible") { // this line is
wrong
... do stuff here ...
}
}

This isn't working at all though...
Any suggestions or help would be greatly appreciated!.
Thanks in advance.
Dave
Jul 23 '05 #1
1 4298
On 9 Aug 2004 16:38:42 -0700, Dave R <dr********@ups.com> wrote:
I'm trying to loop through all the elements in a form, and determine
whether or not the field is visible. Kinda like this:

var TForm = document.form1;

for (i=0;i<TForm.length;i++)
{
if (TForm.elements[i].style.visibility=="visible") { // this line is
wrong
... do stuff here ...
}
}

This isn't working at all though...


Working with inline styles can be quite awkward. This is because when a
value matches what has been imposed by a stylesheet, the respective style
property returns an empty string rather than the actual value. This does
have its advantages though; older browsers don't support values such as
"display: table-row". So, if you hide a table row then want to show it
again, some values have to be given "display: block" whilst others need
"display: table-row". Setting an empty string for the display property
does both, effectively.

In your case, visible elements have a visibility property that matches an
empty string, and 'hidden' when they are hidden. Try:

var form = document.forms['formName'];

for(var i = 0, n = form.length; i < n; ++i) {
var elem = form.elements[i];

if(elem.style && 'hidden' != elem.style.visibility) {
// Element is visible
}
}

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #2

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

Similar topics

2
by: Jon | last post by:
Hi all, I am trying to create a page that contains a number of div elements, with links on the left side of the page allowing the user to select which div to display. Some of the pages contain...
3
by: brett | last post by:
Using DOM in IE, how can I loop through FORMs and access FORM elements in a specific form? For example, www.hotmail.com has about 13 forms. I believe the one displayed is dependent on the URL. If...
0
by: Brett | last post by:
Using DOM in IE (SHDocVw), how can I loop through FORMs and access FORM elements in a specific form? For example, www.hotmail.com has about 13 forms. I believe the one displayed is dependent on...
2
by: libsfan01 | last post by:
hi! i have written a function to make visible elements with a certain id. however i intended it to be used to make visible multiple elements but it only appears to switch on the first element it...
5
by: Ed Jay | last post by:
I have a switch statement that controls which of several containers is displayed or not. It currently looks like: function showHelp(n) { show('vhelp'); //makes parent container visible switch...
3
by: bmerlover | last post by:
I believe my problem lies inside the while loop. When I click the play button on the gui app, it goes inside the while loop, reads the file and calls the necessary function to do what it needs to do....
4
by: mrcw | last post by:
I'm trying to shorten this list Page01.Visible = False Page02.Visible = False Page03.Visible = False Page04.Visible = False Page05.Visible = False ... Page50.Visible = False
3
tuxalot
by: tuxalot | last post by:
Hi All, I have a report that I wish to have list boxes and their corresponding labels visible based on certain criteria. Is there a way to loop this code? Private Sub Report_Activate() '...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.