The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Repeatable Sections How to Calculate a Value

Labels

This Discussion is public

Notifications

I'm building a form for entries into an event. I'm going to use repeatable sections as I don't know how many someone will enter.

  • Collect name, address, etc and the first entry costs $500
  • If they click add entry then they enter the information for the second entry but this one only costs $400
  • Then for entries 3+ it costs $300 each

So if someone adds 3 entries their total cost would be 500 + 400 + 300 = $1200

I added a hidden field in the repeat section so on the outside I can see how many total entries they ended up having but I'm struggling with how to calculate the $ amount they owe.

I want to put something in a field like:

if [126] == 1 then value = 500

if [126] == 2 then value = 900

if [126] > 2 then value = 900 + (([126]-2) * 300)

So that this field will hold the correct total dollar amount which I can then pass onto the payment processor. I'm not real familiar with Formidable Forms so I may be missing something but that's what I'd like to accomplish here.

always seem to find an answer shortly after posting

added javascript to the After Fields section of the settings for the form, the calculation can't be made within the element itself on the form building page

this worked just fine

<script type="text/javascript">
jQuery(document).ready(function($){
$('#field_iqi8k').change(function(){
var val1 = $('#field_iqi8k').val();
if (val1 == '1')
{$("#field_xj5j").val('500.00');}
else if (val1 == '2')
{$("#field_xj5j").val('900.00');}
else
{var val2 = 900 + ((val1-2)*300);
$("#field_xj5j").val(val2);}

$("#field_xj5j").change();
});
});
</script>

 

 

You might want to take a look at this. It should point you in the right direction: http://community.formidableforms.com/help-desk/formidable-forms-repeaters-and-complex-jquery-operations/

I'll be surprised if your code example works on a repeater section. The field ids change for every row added in a repeater section because field ids have to be unique for every element in the HTML Document Object Model.

Yea it works fine, neither ID is in the repeater.

The first value #field_iqi8k is a text field that is read only shown to the user how many entries they have. It gets this value from a hidden field in the repeater section.

Then the other value #field_xj5j is another read only field that holds the total $ amount that is owed and passed onto the payment processor.

Discussion closed.