Skip to main content
Participant
August 30, 2023
Answered

Probleme mit "this.getField"

  • August 30, 2023
  • 1 reply
  • 1027 views

Hallo Zusammen

Ich hab ein Test-Formular erstellt mit 3 Dropdown und jeweils einem Name/Vorname-Textfeld.

Ich möchte nun Folgendes machen. Wenn ich im ersten Dropdown Name wähle, soll das erste Namensfeld aktiv sein, alle anderen nicht. Bei Vorname das Vorname Textfeld, etc.

Wenn ich nun mit meinem Script das erste Dropdown ansteure, funktioniert dies, sobald ich weitere Dropdowns programmiere plötzlich nicht mehr. Was mach ich da wohl falsch.

Dokument liegt bei. Script ist dem Dropdown "Liste_1" unter Berechnungen hinterlegt.

Danke für Eure Hilfe
Urs

This topic has been closed for replies.
Correct answer try67

There are several issues with your code. For starters, there's no field in the file called "Liste_4", which is why you're getting the error message about getField returning null.

Also, you would need to split your code and move it to the Validation event of each field, instead of Calculation, like this:

 

 

// Validation script for "Liste_1"
if (event.value == "Name_1") {
	this.getField("Name_1").readonly = false;
	this.getField("Vorname_1").readonly = true;
	this.getField("Name_2").readonly = true;
	this.getField("Vorname_2").readonly = true;
	this.getField("Name_3").readonly = true;
	this.getField("Vorname_3").readonly = true;
} else if (event.value == "Vorname_1") {
	this.getField("Name_1").readonly = true;
	this.getField("Vorname_1").readonly = false;
	this.getField("Name_2").readonly = true;
	this.getField("Vorname_2").readonly = true;
	this.getField("Name_3").readonly = true;
	this.getField("Vorname_3").readonly = true;
}

 

 

Duplicate it for each of the other drop-downs, adjusting the field-names and values as needed, and it should work.

 

PS. I will move your question to the Acrobat forum, instead of the Reader one.

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 30, 2023

There are several issues with your code. For starters, there's no field in the file called "Liste_4", which is why you're getting the error message about getField returning null.

Also, you would need to split your code and move it to the Validation event of each field, instead of Calculation, like this:

 

 

// Validation script for "Liste_1"
if (event.value == "Name_1") {
	this.getField("Name_1").readonly = false;
	this.getField("Vorname_1").readonly = true;
	this.getField("Name_2").readonly = true;
	this.getField("Vorname_2").readonly = true;
	this.getField("Name_3").readonly = true;
	this.getField("Vorname_3").readonly = true;
} else if (event.value == "Vorname_1") {
	this.getField("Name_1").readonly = true;
	this.getField("Vorname_1").readonly = false;
	this.getField("Name_2").readonly = true;
	this.getField("Vorname_2").readonly = true;
	this.getField("Name_3").readonly = true;
	this.getField("Vorname_3").readonly = true;
}

 

 

Duplicate it for each of the other drop-downs, adjusting the field-names and values as needed, and it should work.

 

PS. I will move your question to the Acrobat forum, instead of the Reader one.

 

Participant
September 6, 2023

Thank you very much. With these adjustments, my form now works.

 

Greetings Urs