Skip to main content
Participating Frequently
Sep 11, 2020 3:30 PM UTC
Question

Hide and Unhide form controls with the click of a button

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 is closed to new replies. Start a new post to keep the conversation going.

15 replies

try67
Community Expert
Community Expert
Sep 14, 2020 4:04 PM UTC

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;
	}
}
Translate
Participating Frequently
Sep 14, 2020 5:29 PM UTC

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.

 

Translate
try67
Community Expert
Community Expert
Sep 14, 2020 5:44 PM UTC

So in what way is it not working? Are there error messages in the JS Console?

Translate
Participating Frequently
Sep 14, 2020 3:38 PM UTC

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.

Translate
Inspiring
Sep 14, 2020 3:44 PM UTC

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

Translate
Participating Frequently
Sep 14, 2020 5:11 PM UTC

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

Translate