Need to show/hide specific fields depending on the value entered in a different field
I am creating a form in Adobe Acrobat Pro where you enter the number of agents, up to nine (and yes, I have the field format set to a number with zero decimals, and validate the value is in range 1-9), in the field "NumberOfAgents". This will then make visible the lines for agents A - I (depending on number entered). Each agent letter has the fields (that correlate to their letter) "A", "Agent_A_Name", "Agent_A_Title", "Agent_A_Signature", which need to switch from display.hidden to display.visible. The fields "Agent_A_Name", and "Agent_A_Title" also need to go from required = false to required = true. I added an action using the trigger Mouse Exit to run a JavaScript with the below. However for some reason whenever I try to enter a value in "NumberOfAgents", it doesn't matter what I put in, the field changes the value to "1". I'd also tried this as an On Blur trigger and had the same results.
if (this.getField("NumberOfAgents").value = "1") {
this.getField("A").display = display.visible;
this.getField("Agent_A_Name").display = display.visible;
this.getField("Agent_A_Title").display = display.visible;
this.getField("Agent_A_Signature").display = display.visible;
this.getField("Agent_A_Name").required = true;
this.getField("Agent_A_Title").required = true;
this.getField("B").display = display.hidden;
this.getField("Agent_B_Name").display = display.hidden;
this.getField("Agent_B_Title").display = display.hidden;
this.getField("Agent_B_Signature").display = display.hidden;
this.getField("Agent_B_Name").required = true;
this.getField("Agent_B_Title").required = true;
[all the way through Agent I];
} else if (this.getField("NumberOfAgents").value = "2") {
this.getField("A").display = display.visible;
this.getField("Agent_A_Name").display = display.visible;
this.getField("Agent_A_Title").display = display.visible;
[etc., etc., etc.....];
}
this continues all the way through to .value = "9", making another letter visible/required all the way through.
I'm sure I'm doing something wrong here, but I can't quite figure out what.
The good news is that with the "1" in the "NumberOfAgents" field, I am getting the desired results for the Agent A fields.
Also, I'm guessing there's something better than the 496 lines I'm using to write all this, but my ability with JavaScript is very basic and I haven't been able to find a way to make it shorter through the days I've spent combing this board for clues/help/inspiration. If anyone has any suggestions there, I'm open to them too.
Thanks for your help!
