Syntax error and no computation?

Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

I am new to programming anything in an adobe created form; I am trying to calculate the shipping cost to be added to the subtotal of an order based on the quantity of items ordered. If the number ordered is less than 5, the shipping cost is 10% of the subtotal, if the number ordered is 5 or more, the shipping cost is zero. I wrote the following custom calculation:

var A=this.getField("TNB").value;

var B=this.getField("Subtotal").value;

var C=0.10*B;

if(TNB=>5){Shipping==0};

else {Shipping==this.getField("C").value};

I am getting the following error: "syntax error 5 at line 6"

Can someone help me

TOPICS
Acrobat SDK and JavaScript

Views

167

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

Syntax error and no computation?

Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

I am new to programming anything in an adobe created form; I am trying to calculate the shipping cost to be added to the subtotal of an order based on the quantity of items ordered. If the number ordered is less than 5, the shipping cost is 10% of the subtotal, if the number ordered is 5 or more, the shipping cost is zero. I wrote the following custom calculation:

var A=this.getField("TNB").value;

var B=this.getField("Subtotal").value;

var C=0.10*B;

if(TNB=>5){Shipping==0};

else {Shipping==this.getField("C").value};

I am getting the following error: "syntax error 5 at line 6"

Can someone help me

TOPICS
Acrobat SDK and JavaScript

Views

168

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
May 02, 2019 0
Most Valuable Participant ,
May 02, 2019

Copy link to clipboard

Copied

The == is wrong in several lines. == is used only in comparisons... does A equal B -- if ( A == B) ). Never used in assignments... set A to B -- A = B


Take great care over this, especially in comparisons. Even after decades of programming I sometimes write  if ( A = B )  with bad results.

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
Reply
Loading...
May 02, 2019 0
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

it is not calculating the shipping cost when the number is less than 5

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
Reply
Loading...
May 02, 2019 0
Adobe Community Professional ,
May 02, 2019

Copy link to clipboard

Copied

What is the value of field "C" ?

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
Reply
Loading...
May 02, 2019 0
Adobe Community Professional ,
May 02, 2019

Copy link to clipboard

Copied

Remove ; after }

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
Reply
Loading...
May 02, 2019 0
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

Removing the semicolon after the } eliminated the syntax error

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
Reply
Loading...
May 02, 2019 0
Most Valuable Participant ,
May 02, 2019

Copy link to clipboard

Copied

Is this a custom calculation script of the "Shipping" field? If so, replace "Shipping==" with "event.value = ".

Also, you never use any of the variables you defined, but you reference an non-existing variable ("TNB") in line 4...

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
Reply
Loading...
May 02, 2019 0
Most Valuable Participant ,
May 02, 2019

Copy link to clipboard

Copied

After changes, if it still doesn't work, please repost the new code, and let us know where the event is - what named field, what kind of event.

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
Reply
Loading...
May 02, 2019 0
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

I have changed the code as below:

var TNB=this.getField("TNB").value;

var B=this.getField("Subtotal").value;

var C=0.10*B;

if(TNB>4){Shipping=0}

else {event.value=this.getField("C").value}

it still shows zero, when TNB is 4 or less.

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
Reply
Loading...
May 02, 2019 0
Most Valuable Participant ,
May 02, 2019

Copy link to clipboard

Copied

Use this:

var TNB = Number(this.getField("TNB").valueAsString);

var SubTotal = Number(this.getField("Subtotal").valueAsString);

if (TNB>4) { event.value = 0; }

else { event.value = SubTotal * 0.1; }

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
Reply
Loading...
May 02, 2019 0
Community Beginner ,
May 02, 2019

Copy link to clipboard

Copied

Thank you very much! this works.

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
Reply
Loading...
May 02, 2019 0