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

Nested if then java statements

New Here ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

I'm working on a return/exchange item form, and I have two statements that I can't seem to figure out how to use proper syntax for (that's the error I'm getting on the very last line; I'm probably missing a close curly brace somewhere). Here is the scenario: If the return is past 90 days, the customer is responsible for paying shipping on the exchanged item; if it's within 90 days, they are not. The second "if" is that shipping is 7.95 or 11% of the total, whichever is greater. I have already defined my variables, and this is the "do it" part of my code that needs help:

if(days>90){ //var days is calculated in code above this snippet, and it works in another form field, so that's not the issue

if(amount<72.30){ //amount is a getField defined in var list

event.value = 7.95;

} else{

event.value = ship; //defined as amount*.11 in my var list

} else{

event.value = 0;

}

TOPICS
JavaScript , PDF forms

Views

709

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
LEGEND ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Tip: it's not "Java". It's JavaScript. This might seem to be just picky, but searching the web for info to learn Java, or looking for help with Java, will give you lots of useless advice.

 

What does it say in the JavaScript console?

Votes

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Try this:

if(days>90){
 if(amount<72.30)
  event.value = 7.95;
 else
  event.value = ship;}
else
event.value = 0;

 

Votes

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Excellen. That worked! I knew it was just some punctuation issues.

Votes

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

LATEST

I would recommend using curly brackets for each if-condition, even if it's not needed. It would make reading the code much easier.

Votes

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 ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

A if can't have 2 else.

Votes

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