Variable to input form via link button

Can anyone help me with this?

I have a list of products, and in each has a button that goes to the form where it is possible to purchase the product

How can I do to automatically populate their name?
thanks

I would put your products into an array in the frontmatter. Try this:

title: Products Page
process:
  twig: true
products:
  - title: Product A
    link: products/product-a
  - title: Product B
    link: products/product-b
---

# My Products

{% for product in page.header.products %}
<a class="button" href="{{ url(product.link) }}">{{ product.title }}</a> 
{% endfor %}

Something like this…

what I wanted was to pre-populate a field from a contact form with the product title

I tried this, but it did not work:

now my code looks like this::

<a href="{{ base_url }}/order-product#name={{ item.title }}">

var hashParams = window.location.hash.substr(1).split('&'); // substr(1) to remove the `#`
for(var i = 0; i < hashParams.length; i++){
var p = hashParams[i].split('=');
document.getElementById(p[0]).value = decodeURIComponent(p[1]);;
}

Does this work, should I leave it or do I have another more appropriate solution?