These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Combo boxes with conditional statements and calculations in LiveCycle

Genie001
Registered: May 19 2010
Posts: 10
Answered

I have a form that has 4 sets of radio buttons; all a repetition of the same calculation. The user selects a RB value (1 of 3 named individually for each exclusion group) and inputs a numerical variable value the user has in another numerical field, and then the calculation is scripted in another numerical field. The calculation depends on which radio button is selected.

I would like to script the buttons to "true or false" value. I found this on a past post and would greatly appreciate help in using.

Quote:
//Using a document level function to test a value against "Off" and return the logical result could be used to set the "required" property:

// Document level function

/// My Question? Do you mean in the XML source page after the time stamp? (Too new to post HTML) If this is not where it is located, then where should this appear?

function ButtonRequired(cValue)
{
/*
Function: return result of comparison of passed value to 'Off"
Input: cValue
Return; logical result of comparsion of passed value to "Off"
*/
if (cValue != "Off") {
return false;
} else {
return true;
}

return;
}
// end function

///My Next Question...And then I am trying to make this the script for comparison where GLBase* is named exclusion group, and the subsequent named buttons are PayrollB*, ReceiptsB* and PerunitB* and the result would be GLCost*. When I hit the period after typing GLBase1 in the coding window, the named buttons were in the drop down list. Would the following coding be…

topmostSubform.Page2.GLCost1::calculate - (JavaScript, client)
if (GLbase1.PayrollB1 == true)
(TotalPayroll.rawValue / 1000) * GLRate1.rawValue
else if (GLbase1.ReceiptsB1 == true)
(TotSubAmount.rawValue / 1000) * GLRate1.rawValue
else if (GLbase1.ReceiptsB1 == true)
NoUnits1.rawValue * GLRate1.rawValue

//My Final Question? :) How does the following script effect the above?

//The on blur action could then run the following JavaScript:

/*
on blur action:
set required property on comparison of the field value to "Off"
*/
this.getField(event.target.name).required = ButtonRequired(event.value);
// end on blur action

Much thanks for your help.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Controling a calculation from radio buttons is not a problem. However, you are mixing scripts from two different forms models. So your questions are out of context and don't make any sense. Since you are using LiveCycle forms I would suggest you watch this video before continuing.

https://admin.adobe.acrobat.com/_a200985228/p87746471/

There are other videos and tutorials here on LiveCycle scripting as well.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Genie001
Registered: May 19 2010
Posts: 10
I went through this tutorial, another two you wrote: http://www.acrobatusers.com/tutorials/creating-radio-checkboxes and Conditional Execution, Converting Acrobat® JavaScript for Use inLiveCycle™ Designer Forms, the Mozilla online JS Guide, a guide put out by Westchester U in PA, and combed the user forums since your reply yesterday.

So, using your mouse up and down method, I added the scripts you provided to each button.
Then in the numerical field, I added the conditional arguments-

topmostSubform.Page2.GLCost1::calculate - (JavaScript, client)
if (GLbase1.PayrollB1 = true)
{
(TotalPayroll.rawValue / 1000) * GLRate1.rawValue;
}
else if(GLbase1.ReceiptsB1 = true)
{
(TotSubAmount.rawValue / 1000) * GLRate1.rawValue;
}
else if(GLbase1.PerUnitB1 = true)
{
NoUnits1.rawValue * GLRate1.rawValue;
}

This got me the result for the first condition, however I can't seem to get the next two to work. And the calculation, regardless of which button I select is based on the first argument.

Greatly appreciate the help. It has been years since I scripted and I am one week into LiveCycle.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Wow, you covered a lot of ground!! But the conditional expressions above are wrong. The "==" operator is for comparison. Just a single "=" does an assignment, so the code above will always select the first condition.

Also, LiveCycle radio buttons have an export value, it is this export value, for the exclusion group (not the individual buttons) that should be tested. For example, if "GLbase1.PayrollB1" is an individual radio button in the "GLbase1" exclusion group, then the code should be testing "GLbase1.rawValue" for the export value of the "PayrollB1" button.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Genie001
Registered: May 19 2010
Posts: 10
I had actually tried that (without quotes around values, though) and it had not worked. However, I noticed on the sample form with your tutorial that the binding tab for the exclusion group looked different; on mine, the Value was there, but not the Item. This was originally done in Acrobat. Maybe when I imported it into LiveCycle, it didn't have the same values? So, I deleted the Acro buttons and created LC buttons, re-did the mouse up/downs, and added '*' to the export values. The binging tab now looked right, and this is the script that works- (except for the "TotalPayroll" which is on a different page and I will look for or start a new post for that)

if (GLbase1.rawValue == 'PayrollB1')
{
(TotalPayroll.rawValue / 1000) * GLRate1.rawValue;
}
else if (GLbase1.rawValue == 'ReceiptsB1')
{
(TotSubAmount.rawValue / 1000) * GLRate1.rawValue;
}
else if (GLbase1.rawValue == 'PerUnitB1')
{
NoUnits1.rawValue * GLRate1.rawValue;
}

Thanks!!!