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

Strange result from if else statement?

Explorer ,
Dec 29, 2017 Dec 29, 2017

I'll try to make this as simple as possible... I have two columns of values (numbers) on a form I'm working on. The end goal for the user is for the value in Column A (TotalField) to equal the value in Column B (VerValue). I have written a function that compares the values, and displays one of two buttons depending on the result: either a red circle if the values are not equal, or a green circle if they are.

Here's where it gets funky. In testing the function, the red circle appeared when the values were equal, and the green when they were not. Upon switching the conditions it displays the correct result. Below is the function (written the way it is currently working, which shouldn't be correct) and the code that calls it (placed in the validation script of each field in Column B). The buttons are named the same as Column B appended with either "_N" (red button) or "_Y" (green button).

function verifyButton(TotalField, VerValue)

{

var VerName = event.target.name;

console.println("Function verifyButton Executed");

// If nothing in Column A, hide both buttons

if (TotalField == 0) {

this.getField(VerName + "_Y").display = display.hidden;

this.getField(VerName + "_N").display = display.hidden;

}

// If Column A does not equal Column B, display red button

else if (VerValue !== TotalField) {

this.getField(VerName + "_Y").display = display.visible; //green button

this.getField(VerName + "_N").display = display.hidden; //red button

}

// If Column A equals Column B, display green button

else if (VerValue == TotalField) {

this.getField(VerName + "_Y").display = display.hidden; //green button

this.getField(VerName + "_N").display = display.visible; //red button

}

}

And an example of a validation script that calls it:

var Total = this.getField("TOTAL_PAYOFF").value; //Value of Column A

var Ver = event.target.value; //Value of Column B

verifyButton(Total, Ver);

I am completely baffled. I've checked and rechecked the button names and they are indeed correct (red equals N, green equals Y). I have no idea why I am getting the opposite result.

TOPICS
Acrobat SDK and JavaScript
824
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 ,
Dec 29, 2017 Dec 29, 2017

Because you're accessing the wrong value. Change this line:

var Ver = event.target.value;

To:

var Ver = event.value;

That will give you the field's new value, instead of its current (ie, old) one.

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
Explorer ,
Dec 29, 2017 Dec 29, 2017

Thank you Gilad. It is sadly still displaying the opposite button, and no longer switches to the other button when it should. Not sure what is going on. I'll keep plugging away at it.

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 ,
Dec 29, 2017 Dec 29, 2017

If you can share the file (publicly or privately) I'll be happy to take a look at it.

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
Explorer ,
Dec 29, 2017 Dec 29, 2017
LATEST

I'll email it to you. Thanks so much!

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