471,316 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 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 4207
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by brett | last post: by
reply views Thread by Brett | last post: by
2 posts views Thread by libsfan01 | last post: by
5 posts views Thread by Ed Jay | last post: by
4 posts views Thread by mrcw | last post: by

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.