Will not go through all the else if statements

New Here ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

The following script works through a value <20, but when a value of 20 or greater, it does not recognize any of the else if statements:

 

var v = Number(this.getField("PlatesOrdered").valueAsString)
if (v<10) event.value = "0.00"
else if (v>9)event.value = "131.99"
else if (v>19)event.value = "128.90"
else if (v>49)event.value = "124.99"
else if (v>99)event.value = "122.21"
else if (v>249)event.value = "118.70"
else if (v>449)event.value = "116.19"
else if (v>999)event.value = "113.79"

TOPICS
PDF forms

Views

42

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Sep 04, 2022 Sep 04, 2022

You can try like this:

var v = Number(this.getField("PlatesOrdered").valueAsString);
if(v<=9)event.value = "0.00";
else if(v>9&&v<20)event.value = "131.99";
else if(v>19&&v<50)event.value = "128.90";
else if(v>49&&v<100)event.value = "124.99";
else if(v>99&&v<250)event.value = "122.21";
else if(v>249&&v<450)event.value = "118.70";
else if(v>449&&v<1000)event.value = "116.19";
else if(v>999)event.value = "113.79";

Likes

Translate

Translate
New Here ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

I see what error I was making and corrected, or at least I thought so. The below script provides correct answers on only 10, 100 , 250 , 1,000. On 20 and 50 units, it will not adjust.  Also, if I have 100 units and change to 10 units, it will not adjust the price to the higher 10.

 

var v = Number(this.getField("PlatesOrdered").valueAsString)
if (v<10) event.value = "0.00"
if ((v>9) && (event.value <20))event.value = "131.99"
if ((v>19)&& (event.value <50))event.value = "128.90"
if ((v>49)&& (event.value <100))event.value = "124.99"
if ((v>99)&& (event.value <250))event.value = "122.21"
if ((v>249)&& (event.value <500))event.value = "118.70"
if ((v>500)&& (event.value <1000))event.value = "116.19"
else if (v>999)event.value = "113.79";

Likes

Translate

Translate

Report

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
Contributor ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

var v = Number(this.getField("PlatesOrdered").valueAsString)
if (v<10) event.value = "0.00"
else if (v>999)event.value = "113.79"
else if (v>449)event.value = "116.19"
else if (v>249)event.value = "118.70"
else if (v>99)event.value = "122.21"
else if (v>49)event.value = "124.99"
else if (v>19)event.value = "128.90"
else if (v>9)event.value = "131.99"

 

I think you need some sleep.

Likes

Translate

Translate

Report

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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

Made corrections, the only values I cannot work 20-49 and 50-99. I have looked at this script and cannot see any difference in those two lines than the other. Does anyone else have better eyes than me?

 

var v = Number(this.getField("PlatesOrdered").valueAsString)
if (v<=9) event.value = "0.00"
if ((v>9)&&(event.value <20))event.value = "131.99"
if ((v>19)&&(event.value <50))event.value = "128.90"
if ((v>49)&&(event.value <100))event.value = "124.99"
if ((v>99)&&(event.value <250))event.value = "122.21"
if ((v>249)&&(event.value <500))event.value = "118.70"
if ((v>499)&&(event.value <1000))event.value = "116.19"
if (v>999)event.value = "113.79"

Likes

Translate

Translate

Report

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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

I tried it this way and everything works but numbers 0 - 9 to show 0.00

var v = Number(this.getField("PlatesOrdered").valueAsString)
if (v<=9)event.value = "0.00"
if (v=>10)event.value = "131.99"
if (v>19)event.value = "128.90"
if (v>49)event.value = "124.99"
if (v>99)event.value = "122.21"
if (v>249)event.value = "118.70"
if (v>449)event.value = "116.19"
if (v>999)event.value = "113.79"

Likes

Translate

Translate

Report

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
Contributor ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

That is not nice code, it will overwrite event.value many times, do not do this. One again, see some big value 500, in you very first code it will pass first else if and will not go further even though it should. Why? Programming 101, else if should be treated the opposite to human logic.

 

You first check the furtherst value...

 

You can also write another way, first check 99, then depending on answer check 19 or 449 and the last check will give the anwser, this is called binary search.

Likes

Translate

Translate

Report

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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

LATEST

You can try like this:

var v = Number(this.getField("PlatesOrdered").valueAsString);
if(v<=9)event.value = "0.00";
else if(v>9&&v<20)event.value = "131.99";
else if(v>19&&v<50)event.value = "128.90";
else if(v>49&&v<100)event.value = "124.99";
else if(v>99&&v<250)event.value = "122.21";
else if(v>249&&v<450)event.value = "118.70";
else if(v>449&&v<1000)event.value = "116.19";
else if(v>999)event.value = "113.79";

Likes

Translate

Translate

Report

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

Make content for your business needs with Adobe Express.

Get started easily with free templates: