Get Radio Button Value Before Submission (javascript)


I’m new to diving deep into Gravity Forms and have limited experience with javascript.

I’m creating a form that performs some “fitness/health” calculations based on user input. The input can be in Metric or Imperial units. The formula will vary depending on the selection.

Ideally, I’d like to calculate and add the results to an empty field, but the only solution I’ve found so far is to override a field. I think it’s because I’m using exponents.

There are two issues I’m trying to figure out.

  1. How to get the value of a radio button before submission?
  2. Is the gform filter I’m using the best for this?
<script>gform.addFilter('gform_calculation_result', function( result, formulaField, formId, calcObj ) {
    if ( formId == '2' && formulaField.field_id == '12' ) {
        var exponent = calcObj.replaceFieldTags( formId, '{:15}', formulaField ),
            weight = calcObj.replaceFieldTags( formId, '{:10}', formulaField );
			height = calcObj.replaceFieldTags( formId, '{:4}', formulaField );
			newHeight= Math.pow( height, exponent );
			unit = radio button  (18)
			if unit == "Metric"{
				bmi =  weight/newHeight;
			} else {
				bmi = 703 * weight/newHeight;
		result = Math.round(bmi);
    return result;
} );
  • Jerime