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?
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…