Home > front end >  What am I misunderstanding when determining if a value is between two numbers?
What am I misunderstanding when determining if a value is between two numbers?

Time:12-22

I have a PDF form that adds up several different answers and displays the sum of these answer at the bottom of the page. I want to take that number, and have a sentence underneath it display three different options depending on the sum.

  • Greater than 60: Proceed

  • between 45 & 60: Consult Sales Lead

  • Less than 45: Decline

I am attempting to run a custom calculation script that takes the sum (which is named "total") and writes the above options, but I'm running into a myriad of errors.

My code I've written is below

var A = this.getField("total").value;
if (A >= 60){
    event.value = "Proceed";
} else {
    if (A <= 45){
        event.value = "Decline";}
    } else {
        if (A < 60 && A > 45){
            event.value = "Proceed, decision made with sales leader";}
}

If I were to only write the below block, I do not get any errors.

var A = this.getField("total").value;
if (A >= 60){
    event.value = "Proceed";
}

I'm a newbie when it comes to most JavaScript, so any help is greatly appreciated! Thanks in advance!

I have based most of my code off of different search results from google. My main source

Below are a few other links I've referenced

CodePudding user response:

You can leave away the

if (A < 60 && A > 45) {

line, because that condition is always true after the two previous conditions.

And then, it should work properly.

Just if you want to stay with that last condition, you would have to close it with a curly brace.

CodePudding user response:

I think I managed to figure it out! For some reason, the addition of the "else" factor was causing syntax errors, so I tried it without and it seems to work as intended!

My code, for anyone that happens to find this, is the following:

var A = this.getField("total").value;
if (A >= 60) {event.value = "Proceed";}
if (A <= 59 && A >= 46) {event.value = "Proceed, decision made with sales leader";}
if (A <= 45) {event.value = "Decline";}
if (A == 0) {event.value = "  ";}

Thanks to everyone that took a look at this, even if you didn't get to comment before I figured it out!

  • Related