document.addEventListener('DOMContentLoaded', function() {
// Get the URL parameters
var params = new URLSearchParams(window.location.search);
// Replace 'celebration_type' with the actual parameter name you're using in your URL
var celebrationType = params.get('celebration_type');
// Ensure the parameter is found
if (celebrationType) {
// URL-decode and replace '+' with space if necessary
celebrationType = decodeURIComponent(celebrationType.replace(/+/g, ' '));
// Get the dropdown element by its name attribute
var dropdown = document.querySelector('select[name="wpforms[fields][65]"]');
// Loop through the dropdown options
Array.prototype.forEach.call(dropdown.options, function(option) {
// Check if the option's value matches the parameter
// Here we must compare the encoded values
if (option.value === decodeURIComponent('You%27ve Been Elfed')) {
// Set the matching option as selected
option.selected = true;
}
});
}
});