简体   繁体   中英

LiveCycle - Multiple calculations dependent upon check boxes selected and an input field?

Doing a form in LiveCycle and using FormCalc. As a part of the form I have 2 check boxes (cbPhoto) & (cbCert), and 2 numeric fields (numPages) and (numResults).

What I would like to achieve is when one or both of the check boxes are selected and an number is entered into (numPages) then do the following calculations and display the results in (numResults).

Calculations: If (cbPhoto) is selected and say for example 5 is entered into (numPages) I want the calculation to work out $20 for the first page and $1 for every page thereafter (so in this case the results would be $24).

If (cbCert) is selected and say for example 5 is entered into (numPages) I want the calculation to work out $22 for the first page and $2 for every page thereafter (so in this case the results would be $30).

If both check boxes are selected and say for example 5 is entered into (numPages) I want both of the above calculations to run (the results being $54).

I want the (numResults) to remain blank until after a number is placed in (numPages) regardless if the check boxes are selected or not.

I have had very limited success with the following code and would be happy to use JavaScript if it will make it work.

A9.#subform[0].A4::calculate - (FormCalc, client)
if (cbP3==1) and (cbC3==1) then
P1-1+20
and
(P1-1)*2+22
else ""
endif 

Any and all help would be greatly appreciated. Cheers

Here is my JavaScript solution. The "calculate" event of numResults will execute whenever any of the other 3 fields change. A non-blank result will be displayed when numPages has a value and at least one of the checkboxes are checked.

form1.#subform[0].cbCert::change - (JavaScript, client)

numResults.execCalculate();

form1.#subform[0].cbPhoto::change - (JavaScript, client)

numResults.execCalculate();

form1.#subform[0].numPages::change - (JavaScript, client)

numResults.execCalculate();

form1.#subform[0].numResults::calculate - (JavaScript, client)

var result = null;

if (numPages.rawValue > 0){
    result = 0;
    if (cbPhoto.rawValue == 1){
        result = numPages.rawValue - 1 + 20;
    }

    if (cbCert.rawValue == 1){
        result += (numPages.rawValue - 1) * 2 + 22;
    }

    if (result == 0) {
        result = null;  //show blank instead of 0
    }
}

//this line sets the value of the results field:
result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM