I've Frankensteined the following script to allow a hidden form field to be populated by a value that has been defined in the URL. This script works, but the problem is that anything following "product=" gets shown, so things like the utm_ parameters as well.
So now I'm trying to figure out a way to get the script to only work for text following "?product=" and/or "&product=" up until the next "&".
var url = location.search;
var product = url.substring(url.indexOf('product=')+8, url.length);
var productStripped = product.replace("%20", " ");
$("#product").val(productStripped);
How can I best achieve this?
Thanks!