Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Loop specific fields

Martins_Migle
Level 2
Level 2

Hello!

Im having a hard time figuring out a loop that would check specific dropdown fields in a form and change their text color based on the dropdowns selectedIndex or rawValue.

Could someone please post a sample script?

Thanks in advance!

4 Replies
Bibhu_Bikash_Na
Level 9
Level 9

Yes, you can do that, but specific dropdowns here means what? Any speific name given or something else?

Martins_Migle
Level 2
Level 2

Yes, they have specific names. I ment that, for example, I have a form with 3 dropdown fields, but I want to loop just 2 of them.

Bibhu_Bikash_Na
Level 9
Level 9

Try this .

var nodeLength = Page1.nodes.length; // Counts the total nodes present in the page

var thisElement;

for (var i=0; i<nodeLength; i++) { // loops through all the nodes

thisElement = Page1.nodes.item(i); // add the items

if (thisElement.className == "field"){ // DropDown is a field so it checks for that

  if (thisElement.name == "Your DDL Name"){ // Checks your DDL name

   //somecode;

   }

}

Thanks,

Bibhu.

Martins_Migle
Level 2
Level 2

Thanks, it kinda works, but it is not quite what Im looking for. The DDL have diferent names

so I should have to put if statements for all those DDL, which would make the loop pointless.

My idea was to put all the dropdowns in an array and then loop them and check there values

something like:

var t = 0

var fields = [ DropDown1, DropDown2, DropDown3, DropDown4 ]

for (var i = 0; i<fields.lenght; i++)

     {

    

     if (Dropdown.selectedIndex == "0")

          {

          t =t++

          }   

     }

The problem is that i dont know how to write code for the if statement that checks the selectedIndex.