Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Convert Javascript: switch(xfa.event.newText) to Formcalc Syntax

Avatar

Level 3

I was wondering if someone could provide me with the syntax for formcalc for the following javascript. This is used to hide or make visible 2 fields based on a value in a drop down list:

switch(xfa.event.newText) {
    case 'A - Approved':
        form1.Page1.2nd_Title.presence = "visible";
        form1.Page1.2nd_Signature.presence = "visible";
        break;
   default:
        form1.Page1.2nd_Title.presence = "hidden";
        form1.Page1.2nd_Signature.presence = "hidden";
        break;
}

Thanks,

Mallard27

1 Accepted Solution

Avatar

Correct answer by
Level 6

Sorry, no simple switch-like statement in FormCalc, although there are convoluted ways to simulate it.  For your example the easiest is if/then/else:

if (xfa.event.newText == "A - Approved") then

     form1.Page1.TextField1.presence = "visible"

     form1.Page1.TextField2.presence = "visible"

else

     form1.Page1.TextField1.presence = "hidden"

     form1.Page1.TextField2.presence = "hidden"

endif

Also, not sure if you can have object names that start with a number, like "2nd_Title".

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

Sorry, no simple switch-like statement in FormCalc, although there are convoluted ways to simulate it.  For your example the easiest is if/then/else:

if (xfa.event.newText == "A - Approved") then

     form1.Page1.TextField1.presence = "visible"

     form1.Page1.TextField2.presence = "visible"

else

     form1.Page1.TextField1.presence = "hidden"

     form1.Page1.TextField2.presence = "hidden"

endif

Also, not sure if you can have object names that start with a number, like "2nd_Title".

Avatar

Level 3

I think I asked the wrong question but you have the right answer. I just realized the switch(xfa.event.newText) is formcalc...I misread this the first time which means I really have no question...but your solution would work.

Thanks,

Mallard27