Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
23

Field script output based on range in another field

New Here ,
Nov 23, 2023 Nov 23, 2023

Hi there,

I am creating a fillable form and have used different scripts to automatically calculate figures or copy information to page 2. I am however stuck on one field I cannot seem to resolve:

On the form section there are 2 fields.

field1: quantity

field2:rate

in the second field I want to output a rate based on the pricing tier we have and based on quantity entered in field 1. 

After that I would just multiply those 2 fields which is easy. I just am struggling with setting the script. These are the attempts I have made but each time it outputs the same rate. I feel like I am close but need help asap.

event.value=Number(ifthisgetField("Students"<=4000))(event.value=1.24);
if(2000<="Students"<4000)(event.value=1.46);
if(1000<="Students"<2000)(event.value=1.67);
if(500<="Students"<1000)(event.value=1.98);
if(250<="Students"<500)(event.value=2.50);
if(150<="Students"<250)(event.value=2.66);
if(100<="Students"<150)(event.value=2.96);
if(25<="Students"<100)(event.value=3.32);

Or
var v1 = this.getField("Students").value;
if (v1 >= 25) {event.value = "3.32";}
else if (v1 >=25 && v1 <100) {event.value = (v1);}
else if (v1 >100) { event.value = "3.32";}

var v1 = this.get.Field("Students").value;
if (v1 >=100&&v1<150) {event.value = (v1);}
else if (v1 >=100 &&v1 <150) {event.value = "2.96";}
else if (v1 >150) {event.value ="2.96";}

event.value=Number(ifthisgetField("Students"<=4000))(event.value=1.24);
if(2000<="Students"<4000)(event.value=1.46);
if(1000<="Students"<2000)(event.value=1.67);
if(500<="Students"<1000)(event.value=1.98);
if(250<="Students"<500)(event.value=2.50);
if(150<="Students"<250)(event.value=2.66);
if(100<="Students"<150)(event.value=2.96);
if(25<="Students"<100)(event.value=3.32);

TOPICS
Edit and convert PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms
847
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2023 Nov 23, 2023

You have a LOT of errors in this code.

If you want to compare the value of a field to fixed values you have to do it like this:

 

var students = Number(this.getField("Students").valueAsString);
if (students>=2000 && students<4000) event.value=1.46;
else if (students>=1000 && students<2000) event.value=1.67;

etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 11, 2023 Dec 11, 2023
LATEST

It was my first time ever trying something like this and was so lost. So you have no idea how thankful I am for your help. It worked and my fillable form is perfect.

Thanks so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines