Missing ; error message

New Here ,
Jun 28, 2019

Copy link to clipboard

Copied

I am trying to make a PDF for school fees automatically calculate when the user enters the number of children in each department (P, H or N). I thought I had the code figured out, but I am getting an error message stating "missing ; before statement 3: at line 4" and it highlights the line I made red. I tried adding a ; at the beginning of that statement, but the error message did not change. Any help would be greatly appreciated.

var c2 = 1950; var c3 = 2150; var c4 = 2350; var c5 = 2550;

var children = this.getField("P").value + this.getField("H").value + this.getField("N").value;

var full = this.getField("P Calc").value + this.getField("H Calc").value + this.getField("N Calc").value);

if (children > 4) {

event.value = Math.min(full,c5);

} else if (children > 3) {

event.value = Math.min(full,c4);

} else if (children > 2) {

event.value = Math.min(full,c3);

} else if (children > 1) {

event.value = Math.min(full,c2);

} else {

full;

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

105

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

Missing ; error message

New Here ,
Jun 28, 2019

Copy link to clipboard

Copied

I am trying to make a PDF for school fees automatically calculate when the user enters the number of children in each department (P, H or N). I thought I had the code figured out, but I am getting an error message stating "missing ; before statement 3: at line 4" and it highlights the line I made red. I tried adding a ; at the beginning of that statement, but the error message did not change. Any help would be greatly appreciated.

var c2 = 1950; var c3 = 2150; var c4 = 2350; var c5 = 2550;

var children = this.getField("P").value + this.getField("H").value + this.getField("N").value;

var full = this.getField("P Calc").value + this.getField("H Calc").value + this.getField("N Calc").value);

if (children > 4) {

event.value = Math.min(full,c5);

} else if (children > 3) {

event.value = Math.min(full,c4);

} else if (children > 2) {

event.value = Math.min(full,c3);

} else if (children > 1) {

event.value = Math.min(full,c2);

} else {

full;

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

106

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
Jun 28, 2019 0
Adobe Community Professional ,
Jun 29, 2019

Copy link to clipboard

Copied

Before the red line remove ) before ;

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...
Jun 29, 2019 0
New Here ,
Jun 29, 2019

Copy link to clipboard

Copied

Thanks, Bernd. I was totally focused on the semicolons due to the text of the error message.

Any idea why it would work up to the last else statement, then always give the full amount instead of c2?

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...
Jun 29, 2019 0
Adobe Community Professional ,
Jun 29, 2019

Copy link to clipboard

Copied

You must use event.value = full;

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...
Jun 29, 2019 0
New Here ,
Jun 29, 2019

Copy link to clipboard

Copied

Sorry, too early in the morning here! I meant the last else if function:

} else if (children > 1) {

event.value = Math.min(full,c2);

It returns full even when c2 is less. I tried modifying the whole thing to use children =, instead of children >, but same problem. It seems like a problem with the definition of c2, but I used the exact same syntax as the other variable definitions. Was there something I needed to do at the beginning of my listing of variables? Thanks so much for your patience, this is my first time trying to write javascript.

This is the current modified script

var c2 = 1950; var c3 = 2150; var c4 = 2350; var c5 = 2550;

var children = this.getField("P").value + this.getField("H").value + this.getField("N").value;

var full = this.getField("P Calc").value + this.getField("H Calc").value + this.getField("N Calc").value;

if (children > 4) {

  1. event.value = Math.min(full,c5);

} else if (children = 4) {

  1. event.value = Math.min(full,c4);

} else if (children = 3) {

  1. event.value = Math.min(full,c3);

} else if (children = 2) {

  1. event.value = Math.min(full,c2);

} else if (children = 1) {

  1. event.value=full

} else {

  1. event.value = "";

}

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...
Jun 29, 2019 0
try67 LATEST
Most Valuable Participant ,
Jun 29, 2019

Copy link to clipboard

Copied

All of these lines are incorrect:

else if (children = 4) {

They need to be:

else if (children == 4) {

A single equals-sign is used to assign a value, not compare it with another.

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...
Jun 29, 2019 0