Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

if or else statement

Avatar

Level 3

I have a dropdown with yes or no in the list when "yes" is selected I want a textfield to appear.

(dropdown is named "Snow" and the textfield is named "Ifyes"

I have the following code

if (Snow.rawValue == "1")

{

           Ifyes.presence = "visible";

}

else

}

          Ifyes.presence = "hidden";

}

It is not working in the "Change" Event

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 5

Oops, my bad. It should be this.boundItem and not this.boundItems. Just remove the s and it should work

View solution in original post

7 Replies

Avatar

Level 5

This will not work in the change event as Snow.rawValue does not contain the correct value since the form is the process of changing it. Only when the change action has completed does the rawValue contain the correct updated value. Instead the object change value is stored in an xfa.event object. xfa.event.newText contains the newly selected item of the drop down ( the display string) so it would be

if ( xfa.event.newText == "Yes")

{

    ...

}

if you bind display values to item values in the dropdown, it would be

if ( this.boundItems ( xfa.event.newText ) == "1" )

{

    ...

}

Avatar

Former Community Member

You could add a textfield and put your script that textfield's change event and then make that new textfield invisible.  Just make sure that your bracket after "else" is the correct way.

Avatar

Level 3

It is still not working for me. This is what I have in the change event:

if ( this.boundItems ( xfa.event.newText ) == "1"

}

Ifyes.presence = "visible"; 

}

else

}

          Ifyes.presence = "hidden";

}

Avatar

Level 5

The javascript syntax is incorrect for the if statement. Should be something like

if ( this.boundItems ( xfa.event.newText ) == "1")

{

    Ifyes.presence = "visible"; 

}

else

{

    Ifyes.presence = "hidden";

}

Have you got the dropdown items set to "1"? and set the script to javascript?

Avatar

Level 3

This is still not working for me.

Language is set for JavaScript

Binding Tab Value for Yes is 1

                                No  is 2

Script is in the change event of the Snow dropdown list

There is no script in the Ifyes textfield

I am at a lost don't know what could be wrong!

Avatar

Correct answer by
Level 5

Oops, my bad. It should be this.boundItem and not this.boundItems. Just remove the s and it should work