Expand my Community achievements bar.

Hiding fields

Avatar

Level 7

Hello,

I have some fields that are hidden or visible depending on the value chosen in 3 DDLs. I have the script on the Change event of the third DDL.

That works fine, (i.e., the correct fields are made visible) unless the user goes back and changes their selection in any field, then the fields don't become hidden again.

Here's my script:

var v1 = form1.page1.sectionOne.positioned2.division.rawValue;
var v2 = form1.page1.sectionOne.positioned2.AssocType.rawValue;
var v3 = form1.page1.positioned3.sectionTwo.windsNtwkAccess.rawValue

if ((v1 == '1') && (v3 == '1'))
{
form1.page4.eitEquipment.presence = "visible";
form1.page4.pcEquip.newReplace.presence = "hidden";
form1.page4.pcEquip.select.selEquip.presence = "hidden";
form1.page4.pcEquip.loaner.presence = "hidden";

} else {
if ((v1 == '1') && (v3 != '1'))
{
form1.page4.eitEquipment.presence = "hidden";
form1.page4.pcEquip.newReplace.presence = "hidden";
form1.page4.pcEquip.select.selEquip.presence = "hidden";
form1.page4.pcEquip.loaner.presence = "hidden";


} else {
if ((v1 == '1') && (v2 == '5'))
{
form1.page4.eitEquipment.presence = "hidden";
form1.page4.pcEquip.newReplace.presence = "hidden";
form1.page4.pcEquip.select.selEquip.presence = "hidden";
form1.page4.pcEquip.loaner.presence = "hidden";

} else {

if ((v1 == '2') && (v2 == '1') && (v3 == '1'))
{
form1.page4.eitEquipment.presence = "hidden";
form1.page4.pcEquip.newReplace.presence = "visible";
form1.page4.pcEquip.select.selEquip.presence = "visible";
form1.page4.pcEquip.loaner.presence = "hidden";

} else {
if ((v1 == '2') && (v2 != '1') && (v3 == '1'))
{
form1.page4.eitEquipment.presence = "hidden";
form1.page4.pcEquip.loaner.presence = "visible";
form1.page4.pcEquip.select.selEquip.presence = "visible";
form1.page4.pcEquip.newReplace.presence = "hidden";

} else {
if ((v1 == '2') && (v2 != '1') && (v3 != '1'))
{
form1.page4.eitEquipment.presence = "hidden";
form1.page4.pcEquip.loaner.presence = "hidden";
form1.page4.pcEquip.select.selEquip.presence = "hidden";
form1.page4.pcEquip.newReplace.presence = "hidden";

}}}}}}

Thanks for your help,

MDawn

7 Replies

Avatar

Level 10

Hi,

If it is a small form then you could use the layout:ready event of page4. Same script, just diffferent event. However the layout:ready event fires every time the user interacts with the form, so it can become a performance issue. See example here: http://assure.ly/nB0Bvz.

You could move the script into a function (in a script object) and then call the function in the exit event of all three dropdowns. The example here show screenshots of script objects etc.: http://assure.ly/yDtfsM.

Hope that helps,

Niall

Avatar

Level 7

That does help, but now I realize the script isn’t working properly. Have I constructed the script accurately? I’m trying to get a combination of selections from division, assocType and windNtkAccess DDLs to cause various subforms to show or hide on page 4 of the form.

Margaret Dawn

Avatar

Level 10

Possibly not Margaret.

A typical if/else statement would look like this:

if (a condition) {

     //Script

}

else if (another condition) {

     //Script

}

else if (another condition) {

     //Script

}

Try structuring the script like this.

Niall

Avatar

Level 7

Is it ok to put three conditions together like I did in my script? ((v1 == ‘1’) && (v2 == ‘2’) && (v3 == ‘1’))

Margaret Dawn

Avatar

Level 10

Hi Margaret,

Sorry for the delay!

Yes, you can include several conditions within the one if statement. Normally I would just include then without the additional brackets. For example:

if (v1 == '1' && v3 == '1') {

     //Script

}

But I suspect that this is not the issue.

Good luck,

Niall

Avatar

Level 7

I also think something else is wrong. A programmer here at work helped me reformat the script to make it easier to read. I posted an issue from that where the subform is showing a space for it but no content.

Margaret Dawn

Avatar

Level 10

Hi Margaret,

i can't check that issue now. However can you double check in LC Designer that the content is set to a presence of visible and that it is only the subform is set to hidden.

Niall