Expand my Community achievements bar.

SOLVED

Change field value based on drop down list selection

Avatar

Level 1

Let me start by saying that I consider myself a complete rookie when it comes to this program but I am learning. I have a drop down box that contains two choices (White or Bright White) Based on the selection in the drop down box I would like to change a field value to reflect the appropraite part number (Alpha numeric if that matters). I will have 10 fields that will be an either/or value based on the selection. I have searched the forums but without understanding the terminology yet it is hard to find the answer.

Thanks for any help.

Wayne

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Oh, OK.  So add the value "Select" to the list, and then under the value tab select the Default: dropdown, and pick the item you want to show up by default.  I think that's what you're looking for.

dd2.jpg

View solution in original post

7 Replies

Avatar

Former Community Member

You will need to write a script to accomplish what you want. Typically when dealing with DDLists the change event is used but in your case I suggest that you do not change the other values until you exit the field ...so use the exit event.

Now you need to determine which value the user chose. In your case there are only two values so you can write an if statement that will check for one value and if it is not that then it must be the other value. All objects have a property that represents the value that is set in them. IN the case of XFA the property is rawValue. So to get the what someone chose woudl be objectname.rawValue. So adding that with our if statement yields:

if (DDlistName.rawValue == "White"){

     set the other objects based on White here

} else {

     set the other objects based on Bright White here

}

Note that you may see the notation this.rawValue. The "this" object refers to the object that is used to call the script...so in our case because you are using the exit event of the DDlist it is the value that the user chose in the list.

Now the last thing is to set the values of those other fields. It would be something very similar .....fieldName.rawValue = "whatever you want to set it to"

Hope that helps

Paul

Avatar

Level 1

Ok not quite sure if I am following you completely but lets

try. The field I'm trying to populate is Text

Field1.  I have "Show" exit, "Language" Javascript, "Run At" Client. Type is "Text Field" Value is "Calculated Read-Only" Calculation Scrip is checked.

In the formula box at the top I have the following.

topmostSubform.Page1.TextField1::exit - (JavaScript, client)
if (DropDownList1.rawValue = "NUFORM™ White"){GEL1PLAAWH} else {GEL1PLAABW}

it's not working so I'm guessing it's not right. I am supposed to set this in the field I want populated correct?

Avatar

Former Community Member

Hopefully this sample helps.  Notice I have the dropdown list selected.  Then I select the exit event in the script editor and add the following script.  In Paul's example he specified the drop down fields name which is exactly right and in this case would be "DropDownList1" as seen in the hierarchy view below.  However, I'm making use of a shortcut by using the "this" operator, which refers to the current field.  If "White" is selected, then I will set the value of the field named TextField1 to "W123", if "Bright White" was selected then I set the value to "BW222".

dd.jpg

Hope this helps,

Scott

Avatar

Level 1

Ok we're almost there I think. here is what I have, and it does work, with one exception.

Clipboard01.jpg

Now when I flip to the Preview tab I get "NUFORM™ White" in the drop down box when I want "Select". If I click on the box and Select "NUFORM™ White" then it populates the box properly but I want people to have to select one or the other but by default to be "Select"

Avatar

Correct answer by
Former Community Member

Oh, OK.  So add the value "Select" to the list, and then under the value tab select the Default: dropdown, and pick the item you want to show up by default.  I think that's what you're looking for.

dd2.jpg

Avatar

Level 1

Perfect!! Thanks for the help.


Avatar

Level 1

HI, I have a similar problem, I have colours which relate to a specific cost. On my drop down box I have listed the colours, given them a value and then using the switch bit of jargon in java, allocated a numeric field that a number appears in so I can use it to calculate the final cost.  The problem I am having is that it won't let me use percentage or decimal points, works fine for whole intergers

Any ideas? I have added my script below, basically I need the value to be 1.4 as it will end up being 40% surcharge on a basic price.

Thanks Tira

var selection = this.boundItem(xfa.event.newText);

switch (selection)

{

  case "1": // Selection 1

    standard.rawValue = "1";

    break;

  case "2": // Selection 2

    standard.rawValue = "1"

    break;

   

  case "3": // Selection 3

    standard.rawValue = "1"

    break;

   

   

  case "4": // Selection 4

    standard.rawValue = "1"

    break;

   

    case "5": // Selection 5

    standard.rawValue = "(140 / 100)"

    break;

   

    case "6": // Selection 6

    standard.rawValue = "(140 / 100)"

    break;

}

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----