Code Snippets
Add query parameter value to hidden field
Add query parameter value to hidden field
Pass through dynamic url values to your forms so you can track things like sales reps, traffic source, etc....
<script>
// Listen for when the HTML document has been completely loaded
document.addEventListener('DOMContentLoaded', function() {
// Function to get a specific query parameter value from the URL
function getQueryParamValue(paramName) {
// Create an object to parse the URL query parameters
const params = new URLSearchParams(window.location.search);
// Return the value of the query parameter (e.g., 'salesRep')
return params.get(paramName);
}
// Call the function to get the 'salesRep' query parameter value
var queryValue = getQueryParamValue('your_query_parameter'); // change to your query parameter name
// Check if the query parameter exists
if (!queryValue) {
// Exit if the parameter is not present in the URL
return;
}
// Get all forms on the current web page
var forms = document.querySelectorAll('form');
// Loop through each form found
forms.forEach(function(form) {
// Find a specific hidden field within the form
var hiddenField = form.querySelector('#your_field_id[type="hidden"]'); // Update selector as needed
// If the hidden field is found, set its value
if (hiddenField) {
hiddenField.value = queryValue;
}
});
});
</script>
Similar Code Snippets
Calculate sizes in CSS
CSS's calc() function allows you to perform calculations to determine CSS property values. It's incredibly useful for responsive design, such as when you need to adjust sizes dynamically. For example, if you want a div to be 100% of the viewport width minus a certain margin, you can use calc():
Get class name from element
A nice little script that will return the first class applied to an element. It's part of our internal slider code, but has lots of uses when other js libraries are involved.
Pull content from another page
404 page need a collection list? Webflow told you it can't happen? We've got you covered. Use this code to pull in the nav or entire page design from another page into your 404.