Hello,
Is it possible to link each selection in my “select form” to different URLs and just using 1 link button?
Thanks in advance.
Angelo
Hello,
Is it possible to link each selection in my “select form” to different URLs and just using 1 link button?
Thanks in advance.
Angelo
Here you go:
<script>
const PRODUCT_ID_TO_URL_MAP = {
"843":"https://funnelish.com#1",
"844":"https://funnelish.com#2"
}
document.querySelectorAll('.mySubmitButton').forEach(btn => {
btn.addEventListener("click", ()=>{
let selectedProductInput = document.querySelector('.product-list .pl-item input[name="product-id"]:checked');
if (!selectedProductInput || !selectedProductInput.value){
console.error("no product selected!")
return;
}
let urlToGoto = PRODUCT_ID_TO_URL_MAP[selectedProductInput.value]
if (!urlToGoto){
console.error("product id not mapped to a valid url, " + selectedProductInput.value)
return;
}
window.open(urlToGoto, "_self")
})
})
</script>
PRODUCT_ID_TO_URL_MAP
values to your actual product IDs and URL you want to redirect to.const PRODUCT_ID_TO_URL_MAP = {
"843":"https://funnelish.com#1",
"844":"https://funnelish.com#2"
}
In the example above, when the product ID
843
is selected then it will redirect tohttps://funnelish.com#1
, and if product ID844
is selected then it will redirect tohttps://funnelish.com#2
.
You can add as many ID/URL mappings as needed.
Hope that helps, do let us know how it goes!
This is very much appreciated. Thank you. Will test it out.