My problem is most likely a pretty simple one (not for me however). I have eight boxes with user entered numbers and one box at the bottom that needs to total the amounts from the other boxes. This total needs to be calculated ONLY when the checkbox next to each user entered number is checked. I am so lost when it comes to this stuff. Any help, without the script-speak or computer elitest terms, would be greatly appreciated. I made the document in word, created a PDF and have edited it entirely through LiveCycle. Thanks for the help.
Solved! Go to Solution.
Views
Replies
Total Likes
Sorry for the confusion:
The text fields, not the checkboxes are set to "hidden." That way they can't be accessed till the corresponding check box is clicked.
form1 is not a script. If you look in the hierarchy pane, the first item should be "form 1".
I have a sample you are welcome to have to dissect. Looking at an example is much easier than trying to explain.
You can use this board to see me a private email with an email address and I'll send it ASAP
Views
Replies
Total Likes
Based on your description, here is a possible solution.
Add 8 text fields to your form named nbr1 thru nbr8
Add a ninth field for the total.
Using formCalc (in the total field):
Sum (nbr1,nbr2,nbr3,nbr4,nbr5,nbr6,nbr7,nbr8)
Now add 8 checkboxes next to each nbr1 thru nbr8
Set nbr1 thru nbr8 as hidden
On each checkbox add (on the click event):
if ($.rawValue==1)then
form1.BodyPage1.nbr1.presence="visible"
else form1.BodyPage1.nbr1.presence="hidden"
endif
BodyPage1 is the name of the subform. Change the nbr reference for each of your 8 boxes
The fields remain hidden and the user cannot enter a number until the box is checked
A little clunky but it works
Sum(.....) does not seem to work with FormCalc. I used 'this=' and it adds up all the amount boxes into the total box but I need them only to add up when the boxes are checked. . I call them First_Amount, Second_Amount, and First_Approve, Second_Approve and so on. The check box addition part was a little confusing. First off, how do I set the check boxes as 'hidden'? How will I be able to access or even see them? Also, when I input the formula, it gives me an error code saying 'form1' is not a legit script. Is there a list of the abbreviations used in FormCalc so that I might better understand what I'm writing?
Thanks for any help, example below.
Views
Replies
Total Likes
Sorry for the confusion:
The text fields, not the checkboxes are set to "hidden." That way they can't be accessed till the corresponding check box is clicked.
form1 is not a script. If you look in the hierarchy pane, the first item should be "form 1".
I have a sample you are welcome to have to dissect. Looking at an example is much easier than trying to explain.
You can use this board to see me a private email with an email address and I'll send it ASAP
Views
Replies
Total Likes
Thanks for getting back to me so fast. I just need to get this form up and running by tomorrow and I know absolutely nothing about code. The whole idea of my form is to provide pictures and recommendations for property managers, give an amount for the possible work to be done, distribute the form and have the client read over and 'approve' what they want done. Once the box is clicked, the amount I input before distributing the form needs to calculate with a total amount they approve ending up at the bottom.
Nathan Goldberg
(206) 229-5688
(425) 822-9487
Views
Replies
Total Likes
Nathan's form requires the user to accept dollar amounts entered in 8 fields. As the check boxes are clicked to signify acceptance, the dollar amounts are totaled below. Here's a solution I came up with but I hope some else has a streamlined solution:
I created 8 check boxes (CB1 - CB8) and eight numeric fields that display the dollar amounts (nbr1 - nbr8). A grand total field and eight hidden fields (total1 - total8)
In each of the hidden fields I added this:
if ( CB1.rawValue == 1 )
{total1 = nbr1.rawValue;}
else {total1 = "0";}
var total = 0;
if ( CB2.rawValue == 1 )
{total2 = nbr2.rawValue;}
else {total1 = "0";}
etc.
And I used formcalc to total the amounts:
Sum(total1,total2,total3,total4,total5,total6,total7,total8)
Anyone have a better way to do this?
Views
Replies
Total Likes
If you are happy to use Formcalc you could do it like this:
Have 8 Numeric Fields called NumericField1 so they would be NumericField1[0], NumericField1[1] etc. and 8 checkboxes called CheckBox1 and they would be CheckBox1[0], CheckBox1[1] etc. and then the total field which say would be NumericField2.
In the click event of each checkbox put:
if ($ == 1) then
NumericField2 = NumericField2 + NumericField1[0] // and make the index of the NumericField match the index of the checkbox
elseif ($ == 0) then
NumericField2 = NumericField2 - NumericField1[0]
endif
Views
Replies
Total Likes
Thanks for the help with this, unfortunately the total amount is registered regardless of checkbox event. My amount boxes are called First_Amount, Second_Amount, and so on and my checkboxes are named First_Approve, Second_Approve, etc. The total amount is called Approved_Total. It helps with the response file. If there is any more info I can provide, please let me know.
Thanks again.
Nathan Goldberg
(206) 229-5688
(425) 822-9487
Views
Replies
Total Likes
Post the script that you are using and we can debug it
Views
Replies
Total Likes
So your script should look like this:
var total = 0;
if ( first_approve.rawValue == 1 )
{total1 = first_amount.rawValue;}
else {total1 = "0";}
This is entered as a "calculate" event into a hidden field named total1.
Add 7 more hidden fields and name each total2 thru total8
total2 script will be:
var total = 0;
if ( second_approve.rawValue == 1 )
{total2 = second_amount.rawValue;}
else {total2 = "0";}
and so on for your remaining 6 fields.
Use the script in a previous post to total your amount
Hi,
Mind if I chime in?
I would do this using formCalc and a loop with a test for each checkbox. Put the script on the Grand Total field Calculate event:
//////////////////////////////////////////////////////////////////////////////
$ = 0
var total = 0
for i = 0 upto 8 do
if (RowItem[i].CheckBoxAccept == "1") then
total = RowItem[i].NumItemAmt + total
endif
continue
endfor
$ = total
//////////////////////////////////////////////////////////////////////////////
Then I would have a "Accept All" checkbox (instead of clicking 9 times if you want to accept everyhing). Put a checkbox in the total row and on the Change event using formCalc like this:
//////////////////////////////////////////////////////////////////////////////
if ($ == "1") then
RowItem[*].CheckBoxAccept = "1"
elseif ($ == "0") then
RowItem[*].CheckBoxAccept = "0"
endif
xfa.form.execCalculate()
//////////////////////////////////////////////////////////////////////////////
These 2 scripts may be one of the shortest ways to fo it. You have to name all the like items the same. And, you can easily adapt this for having multiple instances.
Good luck!
Stephen
Views
Replies
Total Likes
I had thought about doing it like that but the problem with that script is that if you uncheck a box or uncheck and then recheck it you will get the wrong amounts.
Views
Replies
Total Likes
Hi,
Actually, it works perfectly, if I undestand the problem (which I think is totaling the accepted amounts, right?). The grand total adjusts with every checkbox click.Off, On, Off, On....it doedn't matter. It works every time.
The second script is optional--only if you want the user to accept all, or decline all. If they leave it alone, it doesn't do anything. It resides on the Change event--so unless there is a change by the user on that checkbox, it just sits there and does nothing.
Cheers,
Stephen
Views
Replies
Total Likes
I like it - Cleaner and compact
Views
Replies
Total Likes
I feel like a complete idiot here. Like I said, I dont understand any of the scripts or terms used. I'm not sure what a 'loop with a test' is and how to enter it in the field. No here is the 'feeling like and idiot' part comes in. My numeric fileds are First_Amount, Second_Amount, etc. My checkboxes are First_Approve, Second_Approve, etc. I've put eight hidden fields and called them total1, total2, etc. My total amount field is called Approved_Total. Please let me know the script in the most simplified terms and let me know where to put it. Also, the 'show' box title would be helpful. I feel like a loser, but this isn't the easiest skill to learn in two weeks. Thanks again for all the time spent holding my hand on this.
Views
Replies
Total Likes
I GOT IT!!!!
SMARTEST MAN ALIVE, RIGHT HERE.
Thanks to all who helped me with this. I know it must've been a pain in the ass, but please know that I appreciate it.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies