Skip navigation
johndingo44
Currently Being Moderated

dependent drop down list

Apr 8, 2012 6:36 PM

I hope I can explain this properly...

 

Lets say I have a drop down list in box "A"...I want a drop down list in box "B" to display options dependent on what is selected from Box "A".

 

e.g.

If box "A" is selected as "month"...I want box "B" to have pulldown options of "JAN, FEB, MAR" etc

if box "A" is selected as "year"...I want box "B" to give options as "2012, 2011, 2010" etc

 

I am using Livecycle Designer 8.0 if that matters...

 

Can someone provide guidance?

thanks so much in advance!

John

 
Replies
  • Currently Being Moderated
    Apr 9, 2012 3:58 AM   in reply to johndingo44

    Hello,

     

    You can write the script in the PreOpen event of the drop down list boxB as follows:

     

    if(boxA.rawValue == "month")

    {

    boxB.clearItems();

    boxB.addItem("JAN");

    boxB.addItem("FEB");

    boxB.addItem("MAR");

    }

     

     

    if(boxA.rawValue == "year")

    {

    boxB.clearItems();

    boxB.addItem("2012");

    boxB.addItem("2011");

    boxB.addItem("2010");

    }

     

    Thanks,

    Debadas.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 9, 2012 4:12 AM   in reply to Debadas

    Hi John,

     

    Just noticed Debadas posted a solution while a was checking mine works. Mine is basically the same (in the same event) but just wanted to point out that if you are targeting Reader 9 or later then you can use the setItems method which makes things a little easier, as you can load all the items in one hit (though maybe with an older version of Designer that wont work, but thought I might as well add my bit).

     

    switch (DropDownA.rawValue)

    {

        case "Month":

    //      this.setItems("January,February,March,April,May,June,July,August,Sept ember,October,November,December");

            this.clearItems();

            for (var i = 0, currentDate = new Date(2012,0,1); i < 12; i++, currentDate.setMonth(currentDate.getMonth() + 1))

            {

                this.addItem(util.printd("MMMM", currentDate, true))

            }

            break;

        case "Year":

            this.setItems("2012,2011,2010,2009,2008,2007,2006,2005,2004,2003,2002,2001");

            break;

    }

     

    Bruce

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2012 9:37 AM   in reply to Debadas

    I tried this code in LifeCycle. I entered it in the script editor of boxb with the settings: PreOpen, JavaScript, Server. I receive the following error message.

    __________________________________________________________________

    Script failed (language is formcalc; context is xfa[0].form1[0].#subform[0].boxa[0])

    script=if (this.rawValue == GSS)

    {

                   this.parent.OrganizationNumber.selectedIndex = a

                   }

     

     

    Error: syntax error near token "{" on line 2, column 1.

    ___________________________________________________________________

    Below is the script I entered.

     

    form1.#subform[0].boxa::preOpen - (FormCalc, server)

     

    if(boxa.rawValue == "GSS")

    {

    boxb.clearItems();

    boxb.addItem("JAN");

    boxb.addItem("FEB");

    boxb.addItem("MAR");

    }

     

    if(boxa.rawValue == "Healthcare")

    {

    boxb.clearItems();

    boxb.addItem("2012");

    boxb.addItem("2011");

    boxb.addItem("2010");

    }

    ----------------------------------------------------------------

    Either there is an error in my script, or I am not setting the drop-down boxes up properly prior to writing the script. Prior to the script do I need to enter any list items in the right-hand side box for either boxa or boxb? I entered "GSS" and "Healthcare" in boxa and "JAN", "FEB", "MAR", "2012", "2011", "2010". Where does the script pull from when identifying the two different boxes' names? The object->field->caption box or object->binding->name box?

     

    *Step-by-step instructions would be extremely helpful, starting from scratch. ie. "place two blank drop-down menus on the worksheet." and so on.

     

    Thank you in advance!

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2012 12:41 PM   in reply to fistfulwales

    Hi,

     

    A couple of things:

    • The script syntax is JavaScript, but you have set the language to FormCalc. This is throwing the error.
    • If you want to populate boxb, then the script should be in the preOpen event of boxb and NOT in the preOpen event of boxa.

     

    There is an example here: http://assure.ly/jcTahK.

     

    • Drag two dropdowns onto the page.
    • Name them baxa and boxb.
    • Place above script in the preOpen event of boxb (language is JavaScript).
    • Test.

     

    Hope that helps,

     

    Niall

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

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