Skip to main content
Participating Frequently
September 11, 2020
Question

Hide and Unhide form controls with the click of a button

  • September 11, 2020
  • 2 replies
  • 2287 views

I have a PDF form that has 5 lines. 4 of those 5 lines are hidden. If the user wants to add a line, I would like them to click on the button that says "add line". When the user clicks on the button, a new form controls is visable. Right now I have the 5 form controls in the form and 4 of them are hidden. I'm just not sure what the javascript is to allow 1 button to be clicked multiple times to do the same action. Can someone help me with this please?

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
September 14, 2020

Let's say the fields are called Text1 to Text5. You can use this code as the Mouse Up event of your button field to show the next one that's hidden:

 

for (var i=1; i<=5; i++) {
	var f = this.getField("Text"+i);
	if (f.display==display.hidden) {
		f.display = display.visible;
		break;
	}
}
Participating Frequently
September 14, 2020

Thank you for the reponse.

I entered this into the file and it does not seem to be working...

I changed the texted field to what my headers are labeled. I also have 2 things that need to be unhidden on each click. 1 is a drop down and 1 is a text box, both form fields.

 

Nesa Nurani
Community Expert
Community Expert
September 14, 2020

Yes, probably a lot of user error as I'm very new to this. I have my fields names exactly how you have them listed. Would I copy this code multiple times for each row?(i.e. MachineType1.0.0.2 and Quantity1.2 then MachineType1.0.0.3 and Quantity1.3)


You put that code in button field as MouseUp event.

Participating Frequently
September 14, 2020

Basically, I'm looking for code, that when pressed, it adds a drop down and text box. Then when that same button is clicked again, another drop down and text box is added. Then is the same button is clicked for a third time, another drop down and text box is added. So on and so forth. Any help would be greatly appreciated.

Inspiring
September 14, 2020

Wouldn't be easier to already have dropdown and text box there and just show/hide them when button is pressed?

Participating Frequently
September 14, 2020

that is how I currently have it setup but I need them to show up when the button is clicked on, one by one.