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.

Populating Address Fields from an Array based on Drop-down value

  1. Hi. New to Gravity and looking for a bit of advice. Embarrassing to submit such a nube query.

    I'm putting together a simple order form which you can see here:
    http://ec2-107-21-104-54.compute-1.amazonaws.com/wordpress/order/

    When the user selects a "Location" from the drop down, I want to pre-populate the Address field values from a list of addresses that are keyed by Location. Here's a snippet of the file: http://pastie.org/4332286

    The user is free to change the pre-populated Address field values.

    What would be a good way to handle this? The address values will rarely change, so I'm not really worried about managing those... although I could load them in a custom post type or other table. I'm really just looking for your quick take on how to handle this.

    Thanks in advance,

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink
  2. You could do this with conditional logic, but that seems hugely wasteful and hard to maintain.

    You could do this with jQuery, so that when the first drop down is selected, the address for that location is filled in.

    There are a couple solutions and discussions of this online:
    http://stackoverflow.com/questions/558445/dynamically-fill-in-form-values-with-jquery
    http://forum.jquery.com/topic/populate-select-form-field-via-jquery
    http://www.keyframesandcode.com/resources/javascript/jQuery/demos/populate-demo.html

    I would go with jQuery. It's up to you to determine where to store and how to retrieve the addresses. But the process for populating the form fields with retrieved address information can be found online, or in those links. If you need more help with this customization, please let us know.

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink