Auto-populate a field in Form 'A' with an entry from Form 'C' that is dependent on a user-choice lookup field pulling entries from Form 'B'

By: paulus macaulus | Asked: 02/27/2023
ForumsCategory: How-toAuto-populate a field in Form 'A' with an entry from Form 'C' that is dependent on a user-choice lookup field pulling entries from Form 'B'
paulus macaulus asked 2 years ago

Hi,

I am building an estimate form for a client. The question is about 3 forms, 2 with entries used as feeder forms.

1x Main Estimate Form the user fills in

Then feeder forms, of which the below 2 make up my question:
1x Car Database Form - 5 text fields populated with 55,000+ entries to allow the car choice by the user.

1x Body Type Price Modifier Form - 2 text fields - 1 for "Body Type" -- 1 for a "Number" to represent a percentage modifier for each body type.

On the form that the user fills in, there is a series of Lookup fields to select their car to get a price estimate. These 5 fields cascade down from  --> Car Make - Car Model - Car Year -  Body Type - Car Series, pulling its options from the Car Database Form of which one is Body Type.

When the Body Type has been chosen, I need a field on the Main Estimate Form to pull in the number value from the Body Type Price Modifier Form it matches with. This form has an identical list of entries that match the Body Type Text Field in the Car Database Form.

When the body type is chosen by pulling from the Car Database Form, I cannot get a field in the Main Estimate Form (even with intermediary fields to store and give values in the Main Estimate Form, I've tried so many different things....😕) to be populated with the "Number" from the Body Type Price Modifier Form which matches the Body Type chosen by the user pulling from the Car Database form, which I need to match the number needed for that "Body Type" Text Field of which they are both an exact match to each other.

I really hope this is possible, it feels like it should be easily achieved but it seems when I need to populate fields dependent on different form entries, it isn't? If anyone can help it would be greatly appreciated.

2 Answers
paulus macaulus answered 2 years ago

I had to change the way I was looking at it due to deadlines needing to be met. The below does what i need for now. originally i pulled the code from this page:https://formidableforms.com/knowledgebase/javascript-examples/#kb-conditional-calculation

jQuery(document).ready(function($){$('select[name="item_meta[125]"]').change(function(){
var val1 = $("select[name='item_meta[125]']").val();
if (val1 == 'Option 1')
{$("#field_KEY").val('10.00');}
else if (val1 == 'Option 2')
{$("#field_KEY").val('20.00');}
$("#field_KEY").change();
});
});

 I needed more pairings so i asked ChatGPT to look at the code but also change it to use switch instead of else if, all took about 3 mins, Scary Cool stuff!,both versions are below, may be of use again for someone :) 

jQuery(document).ready(function($) {
$('select[name="item_meta[111]"]').change(function() {
    var val1 = $(this).val();
    if (val1 == 'Sedan') {
      $("#field_l416n").val('6.00');
    } else if (val1 == 'Convertible') {
      $("#field_l416n").val('6.50');
    } else if (val1 == 'Coupe') {
      $("#field_l416n").val('4.50');
    } else if (val1 == 'Hatchback') {
      $("#field_l416n").val('1.00');
    } else if (val1 == 'Sport Utility') {
      $("#field_l416n").val('15.00');
    } else if (val1 == 'Targa') {
      $("#field_l416n").val('5.00');
    } else if (val1 == 'Wagon') {
      $("#field_l416n").val('14.00');
    }
    $("#field_l416n").change();
  });
});  

 And with the switch: 

jQuery(document).ready(function($) {
  $('select[name="item_meta[111]"]').change(function() {
    var val1 = $(this).val();
    switch (val1) {
      case 'Sedan':
        $("#field_l416n").val('6.00');
        break;
      case 'Convertible':
        $("#field_l416n").val('6.50');
        break;
      case 'Coupe':
        $("#field_l416n").val('4.50');
        break;
      case 'Hatchback':
        $("#field_l416n").val('1.00');
        break;
      case 'Sport Utility':
        $("#field_l416n").val('15.00');
        break;
      case 'Targa':
        $("#field_l416n").val('5.00');
        break;
      case 'Wagon':
        $("#field_l416n").val('14.00');
        break;
   }
   $("#field_l416n").change();
  });
});    
Walter JonesWalter Jones answered 2 years ago
Be careful with ChatGPT. It last learned formidable forms in 2021, so it will only be as good as its KB.  
paulus macaulus replied 2 years ago

I asked it for help writing the above javascript to expand on the options and then change it to use switch statements, mainly because syntax is always a weak spot for me. No reference to formidable with what i asked ChatGPT. Are you sure it is still capped in 2021? I now pay for ChatGPT Plus, I would have assumed it would be caught up now or in the process of getting there?

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right