Expand my Community achievements bar.

How do I write script to populate a text field with a user's choice from a drop down?

Avatar

Level 3

    I have a drop down from which the user chooses his company name.  If they don't see their company name they choose "not listed"  If they choose "not listed" a second text field pops up and allows them to enter the company name themselves.

I also have a text field on a master page that is acting as a footer.  I would like to populate this field with the company name chosen from the drop down list, or if they chose "not listed" i'd like to populate it with what they typed in the second field.  Does this make sense?

Just getting in to scripting, and up against a deadline.

Thanks!!

12 Replies

Avatar

Level 3

Any help would be greatly aprreciated.  Up against a deadline to get this form ready.  THANKS!

Avatar

Level 7

In the calculate event for the footer on the master page, add this code:

if (p1.ddComp.rawValue == "not listed") this.rawValue = p1.tfComp.rawValue;

else this.rawValue = p1.ddComp.rawValue;

p1 is the name for the page with the dropdown and text field on it. Add whatever hierarchy you need. Since it's on the master page, you'll need to include the page name for the fields' location(s).

Avatar

Level 6

You can set your droplist to allow custom text entry.  Leave the first space on the list blank and check the custom text box.

Use global binding to populate the footer with the text from the droplist

Avatar

Level 3

The Master Page is called MainPage

The DropDown is called AUlist

The hidden second question (List your assesable unit here:) is called AUoption

and

the text field on the Master page that I want to populate is called AUFooter

So do I need to include the name of the master page and the name of the actual text field with a dot in between them?

Thanks you so much!!

Avatar

Level 3

I tried this method before, but I don't want to allow them to enter in to the drop down.  We want to force them to type it in the next blank, but thanks!

Avatar

Level 7

Since it's in the calculate event of the footer, you only need the name of the page that the drop down and text field are on. Otherwise, you can use xfa to find it.

if(xfa.resolveNode("AUlist").rawValue == "not listed") this.rawValue = xfa.resolveNode("AUoption").rawValue;

else this.rawValue = xfa.resolveNode("AUlist").rawValue;

Avatar

Level 3

I can't seem to get this script to work. 

I may not be explaining all this well.

The drop down and the 2nd question that allows a manual entry of the user's company name are on a page called "Questions1a-1d"

The text field I want to populate is on a master page called Page1.  I think I previously told you the wrong name of this.

Avatar

Level 3

What event would I use this script with?

Something other than calculate?

THANKS

Avatar

Level 7

OK, from the information I now have, this code works.

if(xfa.resolveNode("Questions1a-1d.AUlist").rawValue == "not listed") this.rawValue = xfa.resolveNode("Questions1a-1d.AUoption").rawValue;

else this.rawValue = xfa.resolveNode("Questions1a-1d.AUlist").rawValue;

example.png

Now, if you have these in a subform, then you need to add that between the page name and object name. Also, that code is in the calculate event for the footer. That way, anytime the AUlist or AUfooter objects change, the script will run again to check the value for AUlist.

Message was edited by: jasotastic81 forgot to answer the second question

Avatar

Level 3

One more question:

With this particular piece of code I'm not sure where to place it?

Avatar

Level 3

I placed it under the Master Page text field that I wanted to populate and it doesn't seem to be working.  If I choose a selection from the ddrop down it does populate the Master page text box with that choice, but if I choose "Not listed" and type the company anme into the 2nd question it still populates the master page text box with "Not Listed"

Avatar

Level 3

Just figured it out.  I didn't have the capitalization matching.  This works perfectly and it helped me understand scripting with if/else statement.  I can't thank you enough for the help.  Really awesome!!