Expand my Community achievements bar.

SOLVED

Making a selection visible when picking from a dropdown

Avatar

Level 5

Good Day All;

I am putting together a form where I have a dropdown that contains 3 choices. When one of these choices is selected from the dropdown, a table becomes visible for the user to complete.

The issue I have is when the user selects from the drop down, the table does not become visible unless the user clicks inside the drop down again.

I have tried a “click and the exit” event and came up with the same issue.

The following is the code I am using. I would appreciate any help with this.

Chomp

if (this.rawValue == "5") {

term_select.presence = "visible";

}

if (this.rawValue != "5") {

term_select.presence = "hidden";

}

if (this.rawValue == "6") {

temp_select.presence = "visible";

}

if (this.rawValue != "6") {

temp_select.presence = "hidden";

}

if (this.rawValue == "7") {

act_select.presence = "visible";

}

if (this.rawValue != "7") {

act_select.presence = "hidden";

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

You need to use xfa.event.newText to get the selected value.

On the Change event:

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

if (newValue == "5") {

    term_select.presence = "visible";

}

//etc.

View solution in original post

7 Replies

Avatar

Level 10

Hi,

I think you wanted the change event, and then use xfa.event.change instead of the this.rawValue, so;

if (xfa.event.change == "5") {

    term_select.presence = "visible";

}

if (xfa.event.change != "5") {

    term_select.presence = "hidden";

}

if (xfa.event.change == "6") {

    temp_select.presence = "visible";

}

if (xfa.event.change != "6") {

    temp_select.presence = "hidden";

}

if (xfa.event.change == "7") {

    act_select.presence = "visible";

}

if (xfa.event.change != "7") {

    act_select.presence = "hidden";

}

You might also want to add "execEvent("change");" in the initialize event if you haven't set the initial state some other way.

Bruce

Avatar

Level 5

Thank you Bruce;

I have tried your suggestion. For some reason when I select from the dropdown nothing happens. I am running the Java script debugger  and there are no errors being displayed. I have also included   execEvent("change"); in the initialize event.

I started from scratch and created a simple form that only has 3 items in the select. I used your example and again, no sub form became visible, no errors in the java debugger.

I used my old code and I still had the same issue of the selection in the dropdown did not match up with the sub form that became visual.

I then used only 2 if statements and again got the same result.

if (this.rawValue == "2") {

temp_appoint.presence = "visible";

}

if (this.rawValue != "2") {

temp_appoint.presence = "hidden";

}

   

For your example, I am using LiveCycle designer version 8.05.2072. Would this have anything to do with it not working?

Chomp

Avatar

Correct answer by
Level 10

You need to use xfa.event.newText to get the selected value.

On the Change event:

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

if (newValue == "5") {

    term_select.presence = "visible";

}

//etc.

Avatar

Level 10

Hi,

Jono is right in that you can't use this.rawValue in the change event because it has not been set yet, you could write code to update or cancel the change.

Unless you have the "Allow custom text entry" set then xfa.event.newText and xfa.event.change have the same value.

Here is a example doing something similar, https://workspaces.acrobat.com/?d=lJp-9eLLfgr3NVJmoJesYA that might help.

Bruce

Avatar

Level 5

Thak you very much for the example Bruce.

Avatar

Level 5

Thanks Jono. This worked great

Chomp

Avatar

Former Community Member

Hello all,

This is great advice and I am thinking I could use this on one of my forms, the only question I would need to know an answer to is if this script could work on a drop down with multiple options that may need to be selected more than once. So the scenario goes we've got 6 activities that our stakeholder can choose from and a table would populate for them to fill in the details i.e. date; $rate etc however we need the end user to be able to duplicate the one activity they've chosen if they want to claim on that activity more than once (which they're entitled to do). Can I use the above script in this scenario? Would I need to change anything in order to make the drop down active multiple times? Would I just need to create a repeated subform (that becomes visible) with a min and max set?

Hopefully this makes sense.

Any help you can provide would be of great assistance.

Thank you.