Expand my Community achievements bar.

Dropdown calculation selection

Avatar

Former Community Member

Hello forum members,

I just started Livecycle for dynamic pdf files, but got stuck even at the beggining since i am not good at javascript at all. So i have a simple invoice with a table in which i need to select one of the two types of tax 18% and 5%. The selection is made with a dropdown. I also have one column for the quantity and one column for the price. The equations are not a problem [(quantity * price) * 0.18 or 0.05], however the specific cell needs to know what the dropdown selection is for the product row. For example if i select 18% one cell needs to calculate the 18% tax for all the  selected product rows with 18%, and if i select 5% tax calculations are made for those specific rows. How do i check what is selected in the dropdown? Default value is 1 or 18%.

Here is some code i wrote in the 18% cell

if(Row1.TaxDropdown = 1){

          $ = (Price * Quantity) * 0.18

}

Thanks

6 Replies

Avatar

Level 10

You're mixing some JavaScript and FormCalc syntax there. But the biggest problem is the single equals sign for testing the value, one equals sign assigns a value and two equals signs test a value.

JavaScript:

if (Row1.TaxDropdown.rawValue == 1) {

     this.rawValue = (Price.rawValue * Quantity.rawValue) * .18;

}

FormCalc:

if (Row1.TaxDropdown == 1) then

     $ = (Price * Quantity) * .18

endif

Avatar

Former Community Member

Thanks that works but just for the first row. I tried adding Row1[*].TaxDropdown but it seems that the calculation is made for the fist row only and the selection from the dropdown on the rest of the rows are ignored. The rows are added dynamicly with a button. I also changed the code a bit

.

if (Row1[*].TaxDropdown.formattedValue == "5%") then

          $ = (Row1[*].TotalNoTax * Row1[*].TaxDropdown)

endif

Avatar

Level 10

That's not going to work. Is there one field that you are totalling in or is there a series of fields?

Avatar

Former Community Member

It is just one field. Here is an image of how my table looks. So you have price and quantity calculated in the total without tax. Also when you select from the dropdown menu 5% or 18% it displays the tax in the appropriate cell, and this is total for all the rows. I can make it work for only one row but not for the rest, you can select the tax but it's not calculated.

invoice.jpg

Avatar

Level 10

Hey, sorry for the delay, turkey day and work got in the way. Here's a sample if you haven't figured it out yet.

https://workspaces.acrobat.com/?d=ytA5wB4qNlMHfIzEo69*Hw

I've used JavaScript as I'm not that familiar with running loops with FormCalc. I've put the code on the calculate event of the 5% and 18% total fields. Basically you need to loop through the rows and check the value of the dropdown, if it equals the value you are looking for then add the value of the corresponding Subtotal to the calculation. The other total fields are using FormCalc to do the quick math.

Here's the code on the Calculate event of the 5% field:

var nSum = 0;

//get count of rows

var oRows = Table1._Row1.count;

//get references to the fields you need

var oTax = this.resolveNodes("Table1.Row1[*].Tax");

var oSub = this.resolveNodes("Table1.Row1[*].Subtotal");

//loop through the rows and add up values

for (var i = 0; i < oRows; i++) {

          if (oTax.item(i).rawValue == "5%") {

                    nSum += oSub.item(i).rawValue;

          }

}

//write out the needed value

this.rawValue = nSum * .05;

Avatar

Former Community Member

Thank you a lot Jono that is exactly the code i needed, and it works like a charm.