I’m hoping someone out there can help me over a little hurdle. I have a form with essentially 3 fields:
guests (number)
hours (number)
refreshments (yes/no radio button)
The goal of the form is to return a multiplication product based on these three fields (e.g. result = guests * hours * refreshments [where refreshments is either 1 or 1.2 depending on the user’s selection])
My problem is that I don’t understand how to use JS in GF to convert a response on the radio button to a numeric value.
I managed to solve my own problem by assigning numeric values to each of the radio button choices (radio button field --> General tab --> show values).
I probably didn’t know what to Google, but I found it difficult to locate many practical examples of Javascript code for use in GF. For what it’s worth I’m copying my code here for anyone that might search for something similar in the future…
(plopped this code into an HTML field just prior to Field 6 in my form that displayed the calculated value)
Also, probably worth noting that I have very little programming experience, so for all the seasoned programmers out there… sorry if my code is a little rudimentary.
I believe the built in calculations in Gravity Forms can do this without the need for your JavaScript.
The first thing is to assign values to the radio button options as you have done. Be sure that each value is unique, or you will have problems recording the proper answers.
Then, you can add a number fields, and enable the calculation with the checkbox. Then this would be your calculation:
{:1:value} * {:2:value} * {:3:value}
Would that work for you without the need for your own JavaScript?
Thank you Chris! Generally yes, but I oversimplified the Javascript segment I shared. The final Javascript involved was more complex and involved if/then and rounding formulas that the native GF calculation field wouldn’t permit. In my attempt at simplifying my question for the sake of clarity I managed to over-simplify my question and create confusion.
You’re right… based on the info I shared regarding my problem your solution would have worked. Unfortunately there was deeper math involved (not incorporated in the sample I shared) that exempted it from GF’s native calculation options.
I noticed in another post that someone had suggested as a feature improvement that GF incorporate functions (like rounding) into their calculation fields. If any GF staff is watching these threads… I’d up-vote that suggestion.