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

Missing ; error message

Guest
Jun 28, 2019 Jun 28, 2019

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

Before the red line remove ) before ;

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

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?

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

You must use event.value = full;

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

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 = "";

}

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

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.

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