Expand my Community achievements bar.

SOLVED

Can anyone help me out with a Code that will hide all but the first few fields when the form opens

Avatar

Level 3

My form has a section (subform) on top that is always open and then below it it is dynamic and I want certain subforms and sections to open based on users input. I am using the action builder to open the form and have all the fields hidden, but I have way too many subforms and have to individually hide all subforms. Is there a code that will hide all fields for me when the form opens and then I can use the action builder to just open what I need based on a dropdown or radio button?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Using Paul's LockAllFields example, you could place the following JavaScript in the docReady event of the root node (normally "form1").

Please note that the last line is setting the presence of one of the subforms back to visible. Let's call it ShowThisSubform.

// Declare some variables

var allChildElements;

var intNumElements;

var currentElement;

var j;

// Get all the child nodes of the parent element (the root node/"form1")

allChildElements = this.nodes; // "this" will use the element where the script is placed

//Total number of element in the object

intNumElements = allChildElements.length;

// Loop through all the child elements

for (j=0; j< intNumElements; j++) {

     currentElement = allChildElements.item(j);

     // If the element is a subform we'll hide it

     if (allChildElements.item(j).className == "subform") {

          allChildElements.item(j).presence = "hidden";

     }

}

// Show one of the subforms

ShowThisSubform.presence = "visible";

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

Using Paul's LockAllFields example, you could place the following JavaScript in the docReady event of the root node (normally "form1").

Please note that the last line is setting the presence of one of the subforms back to visible. Let's call it ShowThisSubform.

// Declare some variables

var allChildElements;

var intNumElements;

var currentElement;

var j;

// Get all the child nodes of the parent element (the root node/"form1")

allChildElements = this.nodes; // "this" will use the element where the script is placed

//Total number of element in the object

intNumElements = allChildElements.length;

// Loop through all the child elements

for (j=0; j< intNumElements; j++) {

     currentElement = allChildElements.item(j);

     // If the element is a subform we'll hide it

     if (allChildElements.item(j).className == "subform") {

          allChildElements.item(j).presence = "hidden";

     }

}

// Show one of the subforms

ShowThisSubform.presence = "visible";

Niall

Avatar

Level 3

Niall,

You are the man. That is all.