How To Add Post Variables Dynamically to a Link Using JQuery and GravityForms

I recently had to add the ability to dynamically pass the title of a product to a lead form on a B2B eCommerce website.

Anyone can create a button that links to a contact page, but it leaves the question open, “how do we know which product they were interested in without asking the customer to:

  1. Create a product list on the contact form
  2. Ask them after the fact

Using JQuery, we can do this by getting

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var the_heading = $( "h1" ).text();
        the_heading = the_heading.replace(" ", "-");
        var url_path = "/contact/?input_9=";
        $("#lead-button").attr("href", url_path.concat(the_heading));
        //alert(the_heading);
    });
</script>

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.