7 Replies Latest reply: Mar 20, 2012 9:43 AM by NortelT RSS

    if or else statement

    NortelT

      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. Re: if or else statement
          dohanlon Community Member

          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" )
          {
              ...
          }
          
          • 2. Re: if or else statement
            peppemonkey

            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.

            • 3. Re: if or else statement
              NortelT Community Member

              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";

              }

              • 4. Re: if or else statement
                dohanlon Community Member

                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?

                • 5. Re: if or else statement
                  NortelT Community Member

                  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!

                  • 6. Re: if or else statement
                    dohanlon Community Member

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

                    • 7. Re: if or else statement
                      NortelT Community Member

                      Yes, it works!

                       

                      Thanks so much!