Skip to main content
Participating Frequently
November 22, 2021
Answered

Javascript for adobe acrobat, what am I doing wrong

  • November 22, 2021
  • 4 replies
  • 777 views

Hi I am new to doing fillable forms and am having troube making if statements that require 3 conditions.

I am trying to get numbers within a certain range to correct. I will post what I have done. 

 

var PLIGHT1 = Number(this.getField("PLIGHT1").valueAsString);
var LMN = Number(this.getField("LMN").valueAsString);

if (LMN=="7" && (PLIGHT1 => 1 && PLIGHT1 < 767)) {
event.value = (0.99*PLIGHT1);
}
else if (LMN=="7" && (PLIGHT1 => 767 && PLIGHT1 < 1022)) {
event.value = (0.98*PLIGHT1);
}
else if (LMN=="7" && (PLIGHT1 => 1022 && PLIGHT1 < 1552)) {
event.value = (0.98*PLIGHT1);
}
else if (LMN=="7" && (PLIGHT1 => 1552 && PLIGHT1 < 2060)) {
event.value = (0.97*PLIGHT1);
}
else if (LMN=="7" && (PLIGHT1 => 2060 && PLIGHT1 < 2562)) {
event.value = (0.97*PLIGHT1);
}
else if (LMN=="7" && (PLIGHT1 => 2562)) {
event.value = (0.98*PLIGHT1);
}
if (LMN=="6" && (PLIGHT1 > 1 && PLIGHT1 < 799)) {
event.value = (0.96*PLIGHT1);
}
else if (LMN=="6" && (PLIGHT1 => 800 && PLIGHT1 < 1055)) {
event.value = (0.94*PLIGHT1);
}
else if (LMN=="6" && (PLIGHT1 => 1055 && PLIGHT1 < 1613)) {
event.value = (0.95*PLIGHT1);
}
else if (LMN=="6" && (PLIGHT1 => 1613 && PLIGHT1 < 2142)) {
event.value = (0.93*PLIGHT1);
}
else if (LMN=="6" && (PLIGHT1 => 2142 && PLIGHT1 < 2649)) {
event.value = (0.93*PLIGHT1);
}
else if (LMN=="6" && (PLIGHT1 => 2649)) {
event.value = (0.94*PLIGHT1);
}
else event.value = "";

when I try to use it it will only correct with 6 selected if I use 7 it is blank, I would really appreciate it if anyone can point out what I am doing wrong. Thank you.

This topic has been closed for replies.
Correct answer Bernd Alheit

The name of the operator is "greater or equal".

4 replies

Participating Frequently
November 22, 2021

Thank you very much guys I figured it out I was miss an else once it switched to the LMN = 6

Should have been 

else if (LMN=="6" && (PLIGHT1 > 1 && PLIGHT1 < 799)) {
event.value = (0.96*PLIGHT1);

Thanks again for the tips I will be sure to use them in future,

try67
Community Expert
Community Expert
November 22, 2021

You're still making the same mistake I pointed above, though...

Participating Frequently
November 22, 2021

Yeah sorry, I have edited it on my code but I copy pasted of this page without thinking.

Should have been,

else if (LMN==6 && (PLIGHT1 > 1 && PLIGHT1 < 799)) {
event.value = (0.96*PLIGHT1);

try67
Community Expert
Community Expert
November 22, 2021

You've defined LMN as a Number, but then treat it like it's a string.

You should drop the quotes in all of these kind of comparisons in your code:

if (LMN=="7" && ...

Participating Frequently
November 22, 2021

Thanks I removed them

Participating Frequently
November 22, 2021

Also just realised no matter what I type in with 6 selected it times it by 0.96, so is not working at all.

 

Bernd Alheit
Community Expert
Community Expert
November 22, 2021

Why does you the wrong =>?

Correct is >=

Participating Frequently
November 22, 2021

I was trying to do equal or greater than

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
November 22, 2021

The name of the operator is "greater or equal".