Skip navigation
NortelT
Currently Being Moderated

if or else statement

Mar 16, 2012 12:55 PM

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

 
Replies
  • Currently Being Moderated
    Mar 16, 2012 7:02 PM   in reply to NortelT

    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" )
    {
        ...
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 2:46 PM   in reply to NortelT

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2012 7:43 AM   in reply to NortelT

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2012 9:42 AM   in reply to NortelT

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points