Expand my Community achievements bar.

SOLVED

How do I use a radio button state to calculate a value in another field

Avatar

Level 1

I am producing a registration form that uses radio buttons to specify meal and requirements accommodation for individual registrants — separate radio buttons select the meal plan (YES or NO) and accommodation type (NO THANKS, A, B, or D).

I want to query the state of these radio buttons and, if selected (set), calculate the amount to charge for registration in the related sub-total fields (Meal Plan and Accommodations).  In other words, based on the $ charges for YES, A, B, and D on a per registrant basis, I want to enter a $ amount in the sub-total fields "Meal Plan" and "Accommodations".  When NO or NO THANKS is selected then no calculation is necessary.

In the attached form, if a given registrant (say Reg01) chooses to include a meal plan (radio button M01-Y selected) then in the numMEAL sub-total field should increment by $80.  Similarly, if Reg01 wants to book a double room (R01-D) I want to add $268 to the numROOM sub-total field.  It goes without saying that the numMEAL and numROOM fields need to reflect the cumulative amount based on the requirements of all listed registrants (Reg01 thru Reg05)

Example:  I want to use a FormCalc calculation something like . . . (If M01-Y is set then $80) + (If M01-Y is set then $80) + etc . . . to calculate the numMEAL field value and an equivalent expression for the numROOM field.

Also (but don't feel obliged to answer), in the design view how do I configure the radio button selections to show No or NO THANKS as the default selection (set) such that the remaining buttons in the MEAL PLAN and ROOM TYPE groups are not selected (not set) — (I think that would correct the error indications I'm seeing).  I managed to configure this initial radio button state for the form's CITIZENSHIP and PAYMENT TYPE groups but can't seem to do it for the MEAL PLAN and ROOM TYPE groups.

Thanks in advance for your help.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I think this is what you wanted ....see attachment. The issue with the multiple selections in the Design view is because of the - in the name. I changed it for the Rooms as it is being interpretted as a subtraction. You shoudl change them in the Meal radiobuttons as well and that will clear up the design issue you mentioned.

To get the room to add correctly I changed the vaue that is reported to the price of the room. Then on the calculate event of the Accomodations field I simply add all of the room radioButtonList up. The calculate event will fire each time a Room is changed. For the Meals I put the code on the RadioButtonList for each meal (just to show you a different technique). You could od it exactly the same way as the rooms but that is up to you.

Paul

View solution in original post

8 Replies

Avatar

Correct answer by
Former Community Member

I think this is what you wanted ....see attachment. The issue with the multiple selections in the Design view is because of the - in the name. I changed it for the Rooms as it is being interpretted as a subtraction. You shoudl change them in the Meal radiobuttons as well and that will clear up the design issue you mentioned.

To get the room to add correctly I changed the vaue that is reported to the price of the room. Then on the calculate event of the Accomodations field I simply add all of the room radioButtonList up. The calculate event will fire each time a Room is changed. For the Meals I put the code on the RadioButtonList for each meal (just to show you a different technique). You could od it exactly the same way as the rooms but that is up to you.

Paul

Avatar

Former Community Member

Your radio buttons exclusion groups need to be fixed. Currently you have all the radio buttons defined as a value of '1' which yields an 'on' state. Take a look at the attached PDF. I think it will answer your questions. If not, let me know.

foo.PNG

It uses two different techniques to populate the respective field.

// form1.page1.subform1.mealPlan::change - (JavaScript, client)

if (form1.page1.subform1.mealPlan.rawValue == "1") {

     form1.page1.subform1.mealPlanCost.rawValue = 80;

}

else {

     if (form1.page1.subform1.mealPlan.rawValue == "0") {

          form1.page1.subform1.mealPlanCost.rawValue = null;

     }

}

// form1.page1.subform1.roomChoice::change - (JavaScript, client)

var roomOption = form1.page1.subform1.roomChoice.rawValue;

switch (roomOption) {

     case "0":

          form1.page1.subform1.roomCost.rawValue = null;

          break;

     case "1":

          form1.page1.subform1.roomCost.rawValue = 188;

          break;

     case "2":

          form1.page1.subform1.roomCost.rawValue = 228;

          break;

     case "3":

          form1.page1.subform1.roomCost.rawValue = 268;

          break;

     default:

          break;

}

Steve

Avatar

Level 1

Thanks Paul,

I really appreciate your help.  If you have a moment, please see the attached WORD file that has some follow-up questions.  I can tell you're busy (by the number of forum questions you address) so understand if you don't have the time for this follow-up.Once agian, thanks so very much for your help.

Questor 606 (Dave)

The attachment wasn't accepted so I re-sent this "Thank You" with PDF attachments.

Avatar

Level 1

Paul,

Your PDF works exactly as I'd hoped.  Thanks!

If you can spare me the time, I have a couple of follow-up questions, How do I "see" …

1.     the scripting that "changes the value" reported by a radio button?

2.    the scripting that “sums” these radio button values for the sub-totalling fields?

In my Design view, the only info that “appears” in the sub-totalling fields for MEALS and ROOMS is … $ = 0 … which sets the no-sum value to $0.00

(more info in attached PDF -- AdobeForum.pdf)

(also attached my revised form -- DraftForm-Rev02.pdf)

Thanks again for your great support,
Questor 606 (Dave)

Avatar

Former Community Member

1. That info is set on the BInding tab of the radiobutton. If you look at the Object/Binding tab of the RadioButtonList then you can see and adjust all Radiobuttons in that group.

2. The code for subtotalling is on the calculate event of the subtotal field (for Rooms) and on the change event of each RadioButtonGroup (for Meals)

In your screen shot you are only showing one line ... make th escript editor bigger and you will see the rest of the code.

Also the individual radiobuttons in the meal alos have a - in them ...remove the - as per my modifed sample that I sent you earlier.

Paul

Avatar

Level 1

Paul,

Thanks so much for helping build my skill set.  One last question remains.  How do I locate, diagnose, and fix the errors reported when the PDF Form is opened (see attached)?

Cheers,

Questor606 (Dave)

Avatar

Former Community Member

I'm looking into it but I will not be able to get to it until next week.

Paul

Avatar

Level 1

Paul,

I think I figured it out.  The "numeric fields" that make up the set of sub-total calculations (and the overall total as well) were labelled "decimal field".  I could not find out how this label was specified.  The error messages disappeared after I replaced these fields with new ones labelled "numeric field" and setting the "field pattern" to "$1234.21" for both "data" and "display".

Thanks again for all your support,

Questor606 (Dave)

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----