Support

Account

Home Forums Backend Issues (wp-admin) Getting select value on change with jQuery Reply To: Getting select value on change with jQuery

  • It can be complicated, the first thing that you need to be able to do is to detect that a field has changed. This might require targeting a hidden field depending on the field type. Once you do that, in order to get the value of the field you need to use the ACF JS API https://www.advancedcustomfields.com/resources/javascript-api/

    The following has not been tested, it is just an example and some testing/debugging may need to be done

    
    (function($){
      if (typeof acf === 'undefined') {
        return;
      }
      
      // detect change of tax field ??
      // insert the field key of your tax field
      // need to use $(document).on because field may be dynamically inserted and may not exist when the document is ready
      // this might need to target the hidden field, not sure, testing would be required
      // it really depends on the specifics of the field settings
      // you need to inspect the HTML see the structure of the field
      $(document).on('change', '[data-key="field_XXXXXXXXX"] .acf-input select', function(e) {
        
        // once your getting the change event to fire
        // get field value using ACF JS API
        var field = acf.getField('field_XXXXXXXXX');
        var value = field.val();
        
      });
    })(jQuery);