Expand my Community achievements bar.

SOLVED

Make subform visible from drop down list

Avatar

Level 7

I have two drop down lists in my form. I used switch-case to cause the option chosen in dropdown list 1 to populate the available items in dropdown list 2. Based on the option chosen in drop down list 2, I need to make fields visible or hidden. I'm not sure where I get the value for my if statement to make the fields visible or not.

Thanks,

MDawn

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi MDawn,

The populating of drop-down lists (DDL) is done in item pairs: addItem("DDL Item Text Displayed", DDL item value)   For instance: ("Item",1).

You can access the DDL item value using the exit event of the DDL. Placing a script there makes "this" refer to the DDL item value.

So, a script like

if(this.rawValue == "1"){

     subform1.presence = "visible";

}

will reveal the subform after the user selects a DDL item that has the value "1".

Also, you may want to consider using the preOpen of the DDL event to populate the 2nd drop-down box. It allows you to populate the dropdown when it is clicked--this allows you to do a number of things like check any objects value or multiple objects for their values before deciding what items should be populated into the drop-down box. It's pretty powerful way to do it because it opens up a whole range of things you weren't able to do otherwise.

Hope this helps.

Stephen

View solution in original post

5 Replies

Avatar

Correct answer by
Level 7

Hi MDawn,

The populating of drop-down lists (DDL) is done in item pairs: addItem("DDL Item Text Displayed", DDL item value)   For instance: ("Item",1).

You can access the DDL item value using the exit event of the DDL. Placing a script there makes "this" refer to the DDL item value.

So, a script like

if(this.rawValue == "1"){

     subform1.presence = "visible";

}

will reveal the subform after the user selects a DDL item that has the value "1".

Also, you may want to consider using the preOpen of the DDL event to populate the 2nd drop-down box. It allows you to populate the dropdown when it is clicked--this allows you to do a number of things like check any objects value or multiple objects for their values before deciding what items should be populated into the drop-down box. It's pretty powerful way to do it because it opens up a whole range of things you weren't able to do otherwise.

Hope this helps.

Stephen

Avatar

Level 10

Hi,

Have a look at this example: http://assure.ly/h7whb8, which shows the various options for the presence property.

In relation to populating the dropdown2, I would use its preOpen event and look back at the value of dropdown1. See examples here: http://assure.ly/jcTahK. When using the addItem() method, you can specify the Display Item and its Bound value.

addItem("This will be the display item", "This will be the bound value"); 

Depending on the number of items to be added, you could set up a pattern for the bound value, that you could then use in your if statement.

For example, the following script in the preOpen event of dropdown2:

// clear the dropdown displayed value and items

this.rawValue = null;

this.clearItems();


// repopulate the items based on dropdown1

if(dropdown1.rawValue == 1)

{

     this.addItem("Apples", "001");

     this.addItem("Pears", "hidden1");

     this.addItem("Oranges", "002");

     this.addItem("Bananas", "003");

     this.addItem("Grapes", "hidden2");

}

Then in the exit event of dropdown2 you could check the length of its rawValue. If this is greater than 6 characters, then it must be one of the options that you have hardcoded need to hide the other fields:

So in the exit event of dropdown2:

if (this.rawValue.length > 6)

{

     TextField.presence = "hidden";

}

I hope that makes sense,

Niall

snap ;-)

Avatar

Level 7

Thanks to you both for your answers. I got the subforms visible and hidden correctly. Now, my problem is, if the user goes back to ddlist1 and change the option, the now potentially incorrect subform is still visible. I'm not sure which ddlist to affect nor which event.

Thanks again,

MDawn

Avatar

Level 10

Hi,

If you have a look here we have an example of scripting for a null pattern for a dropdown: http://assure.ly/gcXx03. Don't worry about the null pattern.

What you should have a look at is the exit event script for the first dropdown. If the user goes back and makes another selection, then you can clear the dropdown2 and hide the other objects.

So in the exit event of dropdown1, clear dropdown2 and set the presence of the fields to the default state.

Good luck,

Niall

Avatar

Level 7

May I have you take a look at my form? I tried what you suggested and

then the ddlist2 didn't work properly.

I'm forgetting how to upload my forms.

Thanks,

MDawn