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.

Changing default values of text field based on dropdown selection

  1. I have a form in which visitors can set their home municipality (dynamic dropdown populated by custom taxonomy) and also a more exact map location using the WP Geo plugin and two hidden fields (lat and long) as per a tutorial somewhere else in the forum. It's working fine but it requires all visitors to manually enter their location. Not an ideal user experience.

    I want to set the form up so that the lat and long fields are populated dynamically based on the municipality dropdown. I can of course do this after the post has been submitted with PHP but it would be better to have the change take place before the submission happens. Because I'm not managing the day-to-day operations of the site I would like this operation to be handled without external code in functions.php or elsewhere but I can't see an easy way of doing it. So if there is, please let me know.

    Morten

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  2. The only way you could do this if you don't want to do it with PHP is with custom jQuery and attach an event to that drop down using jQuery that then populate the lat/long field. Doing it with PHP is probably the better option. Either way it's not a built in feature so it's going to have to be done as a customization with external code.

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  3. That's what I thought. Just wanted to make sure I wasn't missing some clever workaround. Thanks for the quick response.

    Posted 13 years ago on Friday April 15, 2011 | Permalink
  4. mor10,

    I'm trying to do the exact thing with my form. I want the user to select their city in a dropdown, then have the google map center on that city so they can select their neighborhood.

    I've got several ideas on how to implement this but haven't accomplished it yet. I'll let you know if I figure it out!

    Casey

    Posted 12 years ago on Thursday June 30, 2011 | Permalink
  5. mor10,

    I figured most of this out:

    http://pcsreports.com/survey-single

    and posted the code here:

    http://pastebin.com/zhACadFU

    Casey

    Posted 12 years ago on Thursday July 7, 2011 | Permalink