Skip to main content
Participant
March 1, 2018
Resuelto

Need complete javascript to display form field as empty when divisor is zero

  • March 1, 2018
  • 2 respuestas
  • 1399 visualizaciones

I am making a simple fill in form in Acrobat XI.

I have a sum from one field that I wish to divide by a number that is entered by the person filling in the form, to result in a cost per participant.

I'm using Simplified Field Notation for the division:

Total_Funds/Participant_Count = Cost_per_Participant

for which the person filling in the form enters a number in the Participant_Count field.

I seek the complete JavaScript to enable the Cost_per_Participant field to display as empty (not NAN) until a divisor is entered in the Participant_Count field.

I need some sort of "if" statement and I don't know how to code JavaScript.

Thank you!

Este tema ha sido cerrado para respuestas.
Mejor respuesta de try67

var v1 = Number(this.getField("Total_Funds").valueAsString);

var v2 = Number(this.getField("Participant_Count").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

Edit: Removed a space in the second field name...

2 respuestas

Participant
March 2, 2018

I respectfully ask for the exact Java Script that results in the display of a blank cost per participant cell if the participant count cell Is null. Currently, the cost per participant cell shows as NAN. I need the "if," the "then" and the "else." I have the "else" part. I do not know how to code or write java script, and so do not know how to join the three together into one script.

try67
Community Expert
try67Community ExpertRespuesta
Community Expert
March 2, 2018

var v1 = Number(this.getField("Total_Funds").valueAsString);

var v2 = Number(this.getField("Participant_Count").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

Edit: Removed a space in the second field name...

Participant
March 2, 2018

Thank you so very much, This is exactly what I needed. I will follow this model when developing other forms. Thank you, again, for taking the time to provide a complete answer to my question.

try67
Community Expert
Community Expert
March 1, 2018

Did you try searching the forums? This question was answered many times in the past, including complete code examples.

Participant
March 1, 2018

Yes, I did search for the complete Java Script, and did not find any. I did find plenty of examples to divide by zero, but none for an if/then statement that would act as if participant count (divisor) field = null, then display nothing in cost per participant field, that I will use with the Java script to divide. I don't know how to code, so I need the whole script.

try67
Community Expert
Community Expert
March 2, 2018

Those division-by-zero examples are what you need to use. Just replace the field names with your own and you'll be set.