Copy link to clipboard
Copied
Have a form with fields txtCode.0 to txtCode.20 and txtRow.0 to txtRow.20 created with multiple copies. Want when button butClear is pressed that if field txtCode is null in any rows that the pre-populated value of txtRow is "".
Sure, the code as such can not work.
Where does the index come into the game (or, better, the field name)?
The error gets detected in line 4, which means that it occurs befor that, and that would be in line 3.
Does your document have a field with name "txtCode." ???
Because most likely not, the script fails before even executing line 4, because that field does not exist. The error message by Acrobat says that the getField() method returns null. In this context, null has the meaning of not existing.
B
...Copy link to clipboard
Copied
Do these fields have any formatting being set?
What version of Acrobat are you using?
What is your operating system?
Copy link to clipboard
Copied
No formatting, Acrobat Pro DC, Windows 7.
Copy link to clipboard
Copied
Why not just start out with the field's set to an initial value?
Otherwise you need to write some custom JavaScript to clear the fields and then check each field to see it is a null string and if so then set the value of the field.
Copy link to clipboard
Copied
I am still a novice at scripting. Tried the following script:
//Script to remove txtRow numbers with null txtCode field value
var n = 20;
var txtCRR = this.getField("txtCode.").valueAsString;
var txtRRN = this.getField("txtRow.").valueAsString;
for (var i = 0; i <= n; i++)
if (txtCRR.value=="" ||
txtRRN==null)
(txtCRR.value=txtRRN.value)
Unfortunately getting this JavaScript console error:
TypeError: this.getField(...) is null
4:Field:Mouse Up
Any ideas?
Copy link to clipboard
Copied
Sure, the code as such can not work.
Where does the index come into the game (or, better, the field name)?
The error gets detected in line 4, which means that it occurs befor that, and that would be in line 3.
Does your document have a field with name "txtCode." ???
Because most likely not, the script fails before even executing line 4, because that field does not exist. The error message by Acrobat says that the getField() method returns null. In this context, null has the meaning of not existing.
Back to the original question: As you mention null in the question, there may be a chance that you do not mean "does not exist", but "is empty". Under this assumption, you might try the following:
for (var i = 0 ; i <= 20 ; i++) {
if (this.getField("txtCode." + i).valueAsString == "") {
this.getField("txtRow." + i).value = this.getField("txtRow." + i).defaultValue ;
}
And that should do it…
Copy link to clipboard
Copied
Thanks for your help. I have fields txtCode.0 to txtCode.20 and txtRow.0 to txtRow.20.
Changed the button script to:
//Script for removing row numbers with null txtCode field values
for (var i = 0 ; i <= 20; i++) {
if (this.getField("txtCode." + i).valueAsString == "") {
this.getField("txtRow." + i).value = this.getField("txtRow." + i).defaultValue ;
}
}
But still getting error:
TypeError: this.getField(...) is null
4:Field:Mouse Up
Copy link to clipboard
Copied
When you still get that error, you'd have to carefully check whether your field names are correct, and whether by chance one field is missing.
You could get some additional help by adding the following line as first line in the loop:
console.println("I am in row " + i) ;
When the error occurs, it shows which i value causes the trouble, and you can locate (or, better said, not locate) the fields.
Copy link to clipboard
Copied
Thank you for your help, You were right it was a field naming problem. That's it working now. Much appreciated.
Copy link to clipboard
Copied
You are trying to access the parent field in a hierarchical group of fields.
The parent can control all the common properties of the children fields like readonly, fillColor, etc but not fields that have to be unique to each child field like value.
With hierarchical fields one can access each child field by name or each child field as an element in an array. It appears you are trying to access the child fields by name.
var nDefault = 20;
for(var i = 0, i < 21; i++) {
if(this.getField("txtRow." + i).valueAsStreing == "" || this.getField("txtRow." + i).valueAsString == "") {
this.getField("txtRow." + i).value = nDefault;
}
Copy link to clipboard
Copied
Hit a problem and am wondering if you can help. When I ran the script it looked ok, in that I looked at the first txtCode. null value field and txtRow. was empty. However, in trying test forms the script is only clearing the next row txtRow. value after the last popultated txtCode. field.
I created another form with just these fields and tested it. Script works great. So I know it is not a script issue.
Have you any idea why it is just clearing the first txtRow. value after the last populated txtCode. value, and not the other null txtCode. rows?
Copy link to clipboard
Copied
Just noticed, if I repeat click the button (containing the script) it clears txtRow. after the last populated txtCode. row one row at a time.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now