4 Replies Latest reply on Dec 29, 2017 9:31 AM by Alliosaaa

    Strange result from if else statement?

    Alliosaaa Level 1

      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.