Skip to main content
Participant
July 23, 2024
Question

JavaScript to hide all fields on a form until the first field is entered

  • July 23, 2024
  • 2 replies
  • 481 views

I have been researching and reading through various sites and forums to try and develop a JavaScript and I just cant seem to get it right.

I am developing a form using Adobe Acrobat Pro where the first field on a line requires the user to enter a date into a date form field. I am trying to develop a JavaScript where, until the date is entered, all the other form fields on that same line do not appear. I have named the other form fields 1.a, 1.b, 1.c, 1.d, 1.e, 1.f and 1.g.

 

There are 15 lines to the form so ultimately I don't want any form fields to show until a date is entered on any of the lines.

 

Any help would be appreciated - I am going a little insane trying 🙂

 

This topic has been closed for replies.

2 replies

bebarth
Community Expert
Community Expert
July 23, 2024

If for example your "date" fields are "1.date", "2.date", ... you can write a function in document level:

function visibility(ind) {
	var otherFields=["a","b","c","d","e","f","g"];
	if (event.value=="") {
		for (var i=0; i<otherFields.length; i++) this.getField(ind+otherFields[i]).display=display.hidden;
	} else {
		for (var i=0; i<otherFields.length; i++) this.getField(ind+otherFields[i]).display=display.visible;
	}
}

then call it in validation script of each date field:

visibility(event.target.name.substr(0,event.target.name.indexOf(".")+1));

@+

bebarth
Community Expert
Community Expert
July 23, 2024

What are the names of date fields (e.g: "1.date" for line 1)???

@+