Title: Syncing Dropdown values with Dependencies
Last modified: October 25, 2022

---

# Syncing Dropdown values with Dependencies

 *  Resolved [yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * (@yellowhippo)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/)
 * Hello,
 * I have two dropdown selectors, both with the same series of values (50, 100, 
   500, 1000). I have created a script so that when you change the value of one 
   dropdown, the other changes as well to match. This is all working fine.
 * The problem is…each dropdown value also has a dependency, so when a value is 
   selected, a separate field appears. But this dependency does not trigger when
   using this script.
 * Here is what I have so far:
 * — #dropdownA —
    50 (show field 1) 100 (show field 2) 500 (show field 3) 1000 (
   show field 4)
 *     ```
       -- #dropdownB --
       50 (show field 5)
       100 (show field 6)
       500 (show field 7)
       1000
       ```
   
 * (show field 8)
 * My script:
 *     ```
       jQuery(document).ready(function($) {
       var $selects=$('#dropdownA,#dropdownB').change(function(){
           $selects.not(this).val( $(this).val() );
       })
       ```
   
 * Any help with getting the dependencies to work with this script would be greatly
   appreciated!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16133886)
 * Hello [@yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * You must trigger an onchange event after assigning the value:
 * `$selects.not(this).val( $(this).val() ).change();`
 * But this code generates another issue. You would have an endless loop. So, you
   need some flag to avoid the endless loop.
 * Assuming the dropdown fields in your form are the fieldname1 and fieldname2, 
   respectively, the script to use would be:
 *     ```
       <script>
       fbuilderjQuery(document).one('showHideDepEvent', function () {	
           var $ = jQuery,
       	$selects = $('[id*="fieldname1_"],[id*="fieldname2_"]').change(function () {
       		if(typeof flag != 'undefined') {
       			delete flag;
       			return;
       		}
       		flag = true;
       		$selects.not(this).val($(this).val()).change();
       	});
       });
       </script>
       ```
   
 * Best regards.
    -  This reply was modified 3 years, 7 months ago by [codepeople](https://wordpress.org/support/users/codepeople/).
 *  Thread Starter [yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * (@yellowhippo)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16136647)
 * Unbelievable – that worked brilliantly. Thank you for the solution and the speedy
   reply. You guys are incredible!
 *  Thread Starter [yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * (@yellowhippo)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16136670)
 * Another question – how would I ammend this for more dropdowns, for example 6.
   I have tried the following:
 *     ```
       <script>
       fbuilderjQuery(document).one('showHideDepEvent', function () {	
           var $ = jQuery,
       	$selects = $('[id*="fieldname1_"],[id*="fieldname2_"],[id*="fieldname3_"],[id*="fieldname4_"],[id*="fieldname5_"],[id*="fieldname6_"]').change(function () {
       		if(typeof flag != 'undefined') {
       			delete flag;
       			return;
       		}
       		flag = true;
       		$selects.not(this).val($(this).val()).change();
       	});
       });
       </script>
       ```
   
 * The problem is this runs very slow before executing all dependencies. Is there
   a better way to update this to accommodate more dropdowns?
 * Thank you again!
    -  This reply was modified 3 years, 7 months ago by [yellowhippo](https://wordpress.org/support/users/yellowhippo/).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16136708)
 * Hello [@yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * There is a different problem in your code. You should not delete the flag variable
   until update every dropdown field. Please, edit your code as follows:
 *     ```
       <script>
       fbuilderjQuery(document).one('showHideDepEvent', function () {	
           var $ = jQuery,
       	$selects = $('[id*="fieldname1_"],[id*="fieldname2_"],[id*="fieldname3_"],[id*="fieldname4_"],[id*="fieldname5_"],[id*="fieldname6_"]').change(function () {
       		if(typeof flag != 'undefined') return;
       		flag = true;
       		setTimeout(function(){delete flag;}, 1000);
       		$selects.not(this).val($(this).val()).change();
       	});
       });
       </script>
       ```
   
 * Best regards.
 *  Thread Starter [yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * (@yellowhippo)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16137170)
 * This solution works perfectly. Thank you so much!
 * You’ve provided some great support and I’d like to leave a review or donation.
   Can you please let me know how best I can do this?
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16137231)
 * Hello [@yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * Thank you very much. You can leave a review in the plugin page:
 * [https://wordpress.org/support/plugin/calculated-fields-form/reviews/](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)
 * Best regards.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Syncing Dropdown values with Dependencies’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/syncing-dropdown-values-with-dependencies/#post-16137231)
 * Status: resolved