The conditions must make sense, not conflict with one another, and be testable from concrete values available to the code. The first rule of writing conditional statements is to clearly and simply express the complete set of conditions in English. If( nSubTotal > 100) event.value = nSubTotal * 0.10 The following code is placed in the calculation event for the discount field: var nSubTotal = this.getField("subtotal").value The Acrobat JavaScript code for performing this conditional calculation is exactly the same as our English statement, only it is expressed in JavaScript syntax. To express this idea in English, in the context of our form we might say " If the Subtotal is greater than 100, then set a 10% discount." In this case, we are comparing the value of the order’s subtotal to the constant value 100, then placing a percentage of the subtotal into the discount field if the result of the comparison is true. For example, on an order form we might want to give the customer a discount if they spend more than $100. In computer programming, all decisions are made by comparing values. While there are others, none is as generic and widely used as the "if" statement. In Acrobat JavaScript, the primary element of conditional execution is the "if" statement. It is the ability to execute a piece of code depending on some condition. One of the most important features of any programming language is the ability to make decisions, called Conditional Execution.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |