PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

conditional logic dynamically populated field

  1. Hi, I am dynamically populating a text field with a value from a drop down. I was hoping that the value would initiate some conditional logic to show/hide form fields, however it doesn't seem as though the conditional logic registers when that field has a value written to it.

    To write the value I am using:
    jQuery("#input_4_64").val(selectedValue);
    This inserts the value into that field and it writes correctly but it doesn't fire the logic unless I manually input the "condition".

    Is there a way around this? or to make the conditional logic to "see" when that value changes/gets written?

    Posted 9 years ago on Monday June 18, 2012 | Permalink
  2. David Peralty

    Can you not hook the conditional logic to the selection of the drop down?

    Posted 9 years ago on Monday June 18, 2012 | Permalink
  3. I am not sure how I would do that--well, I can see how to do that, but writing individual conditions would make a very long set of conditional logic and not be quite as dynamic as I am hoping for--the drop down is generated from a Taxonomy. I was hoping to utilize this "filter" I have written

    This is what I am working with:

    add_filter("gform_pre_render_4", "monitor_dropdown");
    function monitor_dropdown($form){
    
    ?>
        <script type="text/javascript">
    
        jQuery(document).ready(function(){
    
          jQuery('#input_4_40').bind('change', function()
            {
    
               //get selected value from drop down;
                var selectedValue = jQuery("#input_4_40").val();
    
                //populate a text field with the selected drop down value
                jQuery("#input_4_64").val(selectedValue);
    
           });
    
        });
    
    $(function(){
    var groupFromValue = {
    
    227: {
            name: 'B-1300SS',
            group: '8'
        },
    
    228: {
            name: 'B-1500SS',
            group: '3'
        },
    
      235: {
            name: 'SG4600-72',
            group: '9'
    }
    
    }
    
    $('select').change(function() {
        var machineName = groupFromValue[$(this).val()].name;
        var machineGroup = groupFromValue[$(this).val()].group;
    	jQuery("#input_4_63").val(machineName);
    	jQuery("#input_4_62").val(machineGroup);
    
    });
    });
        </script>
    <?php
    
    return $form;
    }

    I filter the value and name to come up with group. based on teh data input into the field (in this case (machineGroup) i am trying to use that value to trigger a few input fields on the form. I am doing it this way because i have over 50 machines which are sorted into 3 machineGroup

    Posted 9 years ago on Monday June 18, 2012 | Permalink
  4. Any thoughts on how to make the form register when data has been dynamically entered into a field?

    (bump)

    Posted 9 years ago on Monday June 18, 2012 | Permalink
  5. For anyone else looking for a similar answer:
    You can manually fire the change event after you dynamically populate the field, eg:

    jQuery("#input_4_62").val(machineGroup).change();

    Posted 9 years ago on Tuesday June 19, 2012 | Permalink
  6. David Peralty

    Sorry, I'm not a JavaScript expert, and getting a hold of one of the developers that is takes time. I'm glad you were able to sort it out though.

    Posted 9 years ago on Tuesday June 19, 2012 | Permalink

This topic has been resolved and has been closed to new replies.