-
-
Save nocodesupplyco/15d39b50cdb2767ef620dc5ac7dba978 to your computer and use it in GitHub Desktop.
Set Hidden Input Value From URL Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to get URL parameter values | |
function getUrlParameter(name) { | |
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); | |
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); | |
var results = regex.exec(location.search); | |
return results === null | |
? "" | |
: decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
// Get name and email from URL and add to hidden inputs | |
$(function () { | |
if (window.location.href.indexOf("?name=") > -1) { | |
const name = getUrlParameter("name"); | |
document.getElementById("creator-name").value = name; | |
const email = getUrlParameter("email"); | |
document.getElementById("creator-email").value = email; | |
} else { | |
window.location.replace("https://webflow-pitch.webflow.io/"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment