# Looping through all page objects

**URL:** <https://forum.servoy.com/t/looping-through-all-page-objects/4396>\
**Category:** Classic Servoy\
**Created:** [June 20, 2005, 8:25pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396 "2005-06-20T20:25:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![galexander](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@galexander](https://forum.servoy.com/u/galexander)\
**Post date:** [June 20, 2005, 8:25pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/1 "2005-06-20T20:25:36Z")

</div>

I know in JavaScript on forms you can loop through all the objects on a page, for example to check all text boxes have some kind of value entered in them before a form is submitted. is there a way to do that same thing in servoy. what im looking to do is to be able to go through loop the objects on my form when i start up and if displayType=“COMBOBOX” then i do something to the combo box. is there a way to script that in servoy?

thanks ahead of time,  
galexander

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [June 20, 2005, 8:49pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/2 "2005-06-20T20:49:52Z")

</div>

If you use a very strict naming convenction naming convention you can organize a sort of loop of form elements, just name your elements something like:  
elment\_1, element\_2, …, element\_n

and then for example you can use a loop like this for setting element visibility:

```auto
for ( var i = 1 ; i < 1000 ; i++ )
{
   var element_name = 'element_'+i
   if ( element_name )
   {
     forms.form_name[element_name].visible = false
   }
   else
   {
     break
   }
}

```

I’m going on memory so check the code carefully.  
Beware: it’s not really clever code though, naming your elements this way you loose indication of what they represent so you could find yourself in a hell of a time defining access security or calling a particular element by name.  
Having said that I don’t remember a function to get the dispaly type of a field so I don’t think you will be able to change comboboxes or the like.

---

<div class="post-metadata">

**Author:** ![grahamg](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@grahamg](https://forum.servoy.com/u/grahamg)\
**Post date:** [June 20, 2005, 9:07pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/3 "2005-06-20T21:07:57Z")

</div>

I think the code referred to was posted in Servoy Magazine by David Workman back in March.

> for (var i in elements)  
> {  
> if (elements\*.getName().slice(0,3) == ‘fld’)\*  
> _{_  
> _elements\*.fgcolor = globals.fgcolor;\*_  
> _elements\*.bgcolor = globals.bgcolor;\*_  
> _}_  
> _}_  
> _[/quote]_  
> _The article is a great resource - use this link [http://www.servoymagazine.com/home/2005 … ek\_\_2.html](http://www.servoymagazine.com/home/2005/03/challenge_week__2.html)_  
> _Best regards_  
> _Graham Greensall_  
> _Worxinfo Ltd_

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [June 20, 2005, 9:12pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/4 "2005-06-20T21:12:35Z")

</div>

> for (var i in elements)  
> {  
> if (elements\*.getName().slice(0,3) == ‘fld’)\*  
> _{_  
> _elements\*.fgcolor = globals.fgcolor;\*_  
> _elements\*.bgcolor = globals.bgcolor;\*_  
> _}_  
> _}_  
> _[/quote]_  
> _This is clever but this way you get all form elements not only fields._  
> _If you name only your fields with my naming convention you can loop trough them only._

---

<div class="post-metadata">

**Author:** ![galexander](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@galexander](https://forum.servoy.com/u/galexander)\
**Post date:** [June 20, 2005, 9:23pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/5 "2005-06-20T21:23:20Z")

</div>

i think that code snippet from workman will work for me. wow thanks, i can manipulate that enough i think to get what i need going. I really apprechiate it the help from both of you.

thanks!

---

<div class="post-metadata">

**Author:** ![Harry\_Catharell](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Harry\_Catharell](https://forum.servoy.com/u/Harry_Catharell)\
**Post date:** [June 21, 2005, 10:47am UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/6 "2005-06-21T10:47:44Z")

</div>

Hi Nicola,

> ngervasi:
> 
> > for (var i in elements)  
> > {  
> > if (elements\*.getName().slice(0,3) == ‘fld’)\*  
> > _{_  
> > _elements\*.fgcolor = globals.fgcolor;\*_  
> > _elements\*.bgcolor = globals.bgcolor;\*_  
> > _}_  
> > _}_  
> > _[/quote]_  
> > _This is clever but this way you get all form elements not only fields._  
> > _If you name only your fields with my naming convention you can loop trough them only.[/quote]_  
> > _The ‘if’ condition within the loop deals with that sort of scenario as the formatting will only be applied to elements which begin ‘fld’_  
> > _So there has been an implied naming convention here that all field element names will begin ‘fld…’_  
> > _This then becomes fairly extensible in that your naming convention can handle many types of objects and then target only those specific object types for formatting_  
> > _Cheers_  
> > _Harry_

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [June 21, 2005, 11:19am UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/7 "2005-06-21T11:19:30Z")

</div>

> Harry Catharell:  
> The ‘if’ condition within the loop deals with that sort of scenario as the formatting will only be applied to elements which begin ‘fld’
> 
> So there has been an implied naming convention here that all field element names will begin ‘fld…’
> 
> This then becomes fairly extensible in that your naming convention can handle many types of objects and then target only those specific object types for formatting
> 
> Cheers  
> Harry

Wooppss… I didn’t notice that.

Late hours lead to errors… errors lead to rage, rage leads to hate and hate leads to the darkside!

![:-)]( "Smile")

---

<div class="post-metadata">

**Author:** ![Harry\_Catharell](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Harry\_Catharell](https://forum.servoy.com/u/Harry_Catharell)\
**Post date:** [June 21, 2005, 1:04pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/8 "2005-06-21T13:04:50Z")

</div>

Have patience, young paduan and trust in the Force ![:-)]( "Smile")

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [June 21, 2005, 1:54pm UTC](https://forum.servoy.com/t/looping-through-all-page-objects/4396/9 "2005-06-21T13:54:32Z")

</div>

> Harry Catharell:  
> Have patience, young paduan and trust in the Force ![:-)]( "Smile")

I will, my Master. ![:-)]( "Smile")
