• Resolved vi54

    (@vi54)


    Hi, I have a simple dropdown list.

    I generate an URL with some variables, I was wondering if it’s possible to assign the drop-down menu item to that whats given in the URL

    For example:
    The variable is a ‘pass back’ and named
    results_delivery (just like the slug of that dropdown list)
    {variable:results_delivery}

    I tried to add this variable to:
    default option and/or placeholder

    drop-down list options:
    48 Hours
    Standard Delivery

    Under no condition, I can make the URL variable to assign the correct item in the list

    myexampleurl.com/&results_delivery=48%20Hours

    I also tried to assign an index as I thought it would make sense but that doesn’t work.
    myexampleurl.com/&results_delivery=0

    Thanks for your expertise.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor christiechirinos

    (@christiechirinos)

    Hi Vi, thanks for using Caldera Forms 🙂 This is an interesting use, I would recommend setting up that URL as you want it in a hidden single line field or paragraph field, and then using the default value of that field as a magic tag in whatever else you need to do.

    I hope this helps, let me know if you have any additional questions and I’ll do my best to help.

    Hey, if I understand correctly, I’ve been trying to do something similar and this jQuery seems to work for me! If you’re still looking for a solution or just to know.

    Just be sure to use “?” instead of “&” in the URL. This code should be placed on the page with the form.

    $(document).ready(function() {
      // Construct URL object using current browser URL
      var url = new URL(document.location);
    
      // Get query parameters object
      var params = url.searchParams;
    
      // Get value of delivery results
      var results_delivery = params.get("results_delivery");
    
      // Set it as the dropdown value
      $("#DROPDOWN-ID").val(results_delivery);
    });
    • This reply was modified 5 years, 4 months ago by w7th.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘select from dropdown menu based on url variable’ is closed to new replies.