Skip to main content
Inspiring
June 23, 2021
Answered

Forms: Telling another form field to be blank if this field is blank

  • June 23, 2021
  • 2 replies
  • 6139 views

I created a form set with many fields in rows where if the field is empty there is a default message in it to give the user info on how to fill it. Example:

// If field is blank, display this text 
if (!event.value) { event.target.fillColor = ["RGB", 255/255, 221/255, 170/255]; event.value = "Year, Make, and Model" } else { if (event.value) { event.target.fillColor = color.transparent; } }

 

In this row of several fields, my user wants to know if it's possible if the first row is intentionally left blank by filling in with a space character, could the remainng fields in that row all be made blank automatically?

 

Say there are seven fields... is possible to make fields two through seven say something in the script to the affect of the above format, but with an addtion of "if the first field in this row is intentionally blank, then make this field intentionally blank"?

This topic has been closed for replies.
Correct answer Nesa Nurani

Nesa, thank you for your help in this topic and others recently. I appreciate it. Here is what I've tried to come up with but I'm having syntax error reports and I'm not sure what the problem is. Acrobat has line 7 flagged with "Syntax Error 6".

 

// Look for value of first field in the row. If it's a blank space, then put a blank space in this field
if (this.getField("Vehicle Count 10.0").valueAsString==" ") event.value = " ";
// or if the field is blank, then add a light yellow fill color and put the text "address" in the field
else {if (!event.value) event.target.fillColor = ["RGB", 255/255, 221/255, 170/255];
event.value = "Address";
} else {
// or if the value is anything other than a space or a blank, then keep that text and make the fill color transparent
if (event.value) {
event.target.fillColor = color.transparent;
}

 

 


You are using curly brackets at wrong place,try like this:

if (this.getField("Vehicle Count 10.0").valueAsString==" ")
event.value = " ";
else if (!event.value){
event.target.fillColor = ["RGB", 255/255, 221/255, 170/255];
event.value = "Address";}
else if (event.value)
event.target.fillColor = color.transparent;

 

I assume you use script in calculation, as I already told you in previous post about "Address" last condition will overwrite color as soon as you change something in the file ( like check checkbox or enter value in another field...etc)

2 replies

try67
Community Expert
Community Expert
June 24, 2021

Yes, it is. The basic code is something like this:

 

if (this.getField("Name of first field in row").valueAsString=="") event.value = "";

Nesa Nurani
Community Expert
Community Expert
June 24, 2021

If he use space character it should be ==" ".

Nesa Nurani
Community Expert
Community Expert
June 29, 2021

That works, Nesa. I'm a low-level Javascript user so I appreciate your looking at my code and seeing where I'm not setting it correctly. Here are the results where I put your code in two fields of the form...


Sorry I'm not sure what exactly is problem on photo?

JR Boulay
Community Expert
Community Expert
June 23, 2021

Short answer is yes.

Long answer requires to know how fields are named.

Acrobate du PDF, InDesigner et Photoshopographe