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:
- Create a product list on the contact form
- 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>
Leave a Reply