Expand my Community achievements bar.

Show text field based on values of 2 other fields

Avatar

Level 1

Hi

I have some text fields that only need to be filled in if the values in 2 other fields meet certain conditions. One of these fields is a dropdown box the other is a tick box. So the hidden text field will appear if:

  • The dropdown box = VALUE1

                         AND

  • The tick box IS selected

Otherwise the textbox is hidden.

I'm not sure where to run the code as it is based on 2 conditions rather than 1.

Any help would be much appreciated.

Thanks

4 Replies

Avatar

Level 7

Hi,

You might need to add code to both the DropDownList and the CheckBox so that it doesnt matter which one is selected last.

Using

DropDownList1

CheckBox1

TextField1

CheckBox1: change (Javascript)

if (this.resolveNode("DropDownList1").rawValue == "Value1" && this.resolveNode("CheckBox1").rawValue == "1") {

  this.resolveNode("TextField1").presence = "visible";

}

else

{

TextField1.presence = "invisible";

}

What it does: When the checkbox is checked (rawValue ==1) AND the dropdownlist's rawValue is Value1, TextField1 will be visible. If either is false, TextField1 is invisible (or hidden if you want to do that). && means both items are resolved. If you use & instead and the first half is true, the second part wont be considered in the code.

You can check and uncheck the checkbox to show and hide the field.

Avatar

Level 1

Thank you for your reply. I am having trouble getting it to work correctly.

If I change the tick box to another dropdown what would the correct code be?

So dropdown1 = "text1" AND dropdown2 = "text2"

textfield1 = visible

else

textfield2 = hidden.

Avatar

Level 7

Hi,

I am assuming you mean TextField1 is hidden. Both DropDownLists need a Change event.

Using

DropDownList1

DropDownList2

TextField1

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

DropDownList1 change: (javascript)

if ($.boundItem(xfa.event.newText) == "text1" && this.resolveNode("DropDownList2").rawValue == "text2") {

  this.resolveNode("TextField1").presence = "visible"; //show if true

}

else

  this.resolveNode("TextField1").presence = "hidden"; //hide if false

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

DropDownList2 change: (javascript)

if (this.resolveNode("DropDownList1").rawValue == "text1" && $.boundItem(xfa.event.newText) == "text2") {

  this.resolveNode("TextField1").presence = "visible"; //show if true

}

else

  this.resolveNode("TextField1").presence = "hidden"; //hide if false

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

The DropDownLists (DDL) have list items text1 in DDL and text2 in DDL2. When either is changed the code is run. If the conditions are met (both text1 and text2 selected) then the TextField1 is shown. If either DDL has something else selected, TextField1 will be hidden.

See how this goes.