Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

If-And statements

Avatar

Level 7

Hi,

I have made some pretty cool PDF forms and have some background with programming, but not so much with javascript.

I have created an order form of sorts. In the form, the user places a 1 or more in the order column next to the item they wish to order. After selecting all their items, they click a button to complete the order. When the button is clicked I am using if statements to determine which fields are greater than or equal to 1 and copying that order number and a description to a text field.

The problem i have is that when using for example three separate if statements, only the first item that meets the criteria is copied. If I use else if, only the last one that meets the criteria is copied. What i need is like an 'and' command so that I can concatenate multiple items in the one text field. I can concatenate within one if, but i need to concatenate it with the next true result.

This what i have tried: on the button click event

-Order is the field the user changes.

-OrderPlaced is the text field to be filled in with the order - it will get text like "1 X Bacon and Egg Roll" and has a carriage return for the next item.

if (this.resolveNode("TableBreakfast.Row1.Order").rawValue >= 1) {

  this.resolveNode("form1.#subform[1].OrderPlaced").rawValue = this.resolveNode("TableBreakfast.Row1.Order").rawValue + " X " + "Bacon and Egg Roll" + "\n";

}

if (this.resolveNode("TableBreakfast.Row2.Order").rawValue >= 1) {

  this.resolveNode("form1.#subform[1].OrderPlaced").rawValue = this.resolveNode("TableBreakfast.Row2.Order").rawValue + " X " + "Banana, Pear & Raspberry Loaf - Plain" + "\n";

}

if (this.resolveNode("TableBreakfast.Row3.Order").rawValue >= 1) {

  this.resolveNode("form1.#subform[1].OrderPlaced").rawValue = this.resolveNode("TableBreakfast.Row3.Order").rawValue + " X " + "Banana, Pear & Raspberry Loaf with Raspberry Ricotta" + "\n";

}

What i am trying to achieve is to have a second page with a basic order summary that is easier to read. The order page is quite congested with over 50 items.

Any help would be appreciated

1 Accepted Solution

Avatar

Correct answer by
Level 7

Never mind, solved it. The fault was with my code. I needed to add the existing contents to the additional contents.

if (this.resolveNode("TableBreakfast.Row1.Order").rawValue >= 1) {

  this.resolveNode("form1.#subform[1].OrderPlaced").rawValue = this.resolveNode("form1.#subform[1].OrderPlaced").rawValue + this.resolveNode("TableBreakfast.Row1.Order").rawValue + " X " + "Bacon and Egg Roll" + "\n";

}

View solution in original post

1 Reply

Avatar

Correct answer by
Level 7

Never mind, solved it. The fault was with my code. I needed to add the existing contents to the additional contents.

if (this.resolveNode("TableBreakfast.Row1.Order").rawValue >= 1) {

  this.resolveNode("form1.#subform[1].OrderPlaced").rawValue = this.resolveNode("form1.#subform[1].OrderPlaced").rawValue + this.resolveNode("TableBreakfast.Row1.Order").rawValue + " X " + "Bacon and Egg Roll" + "\n";

}