// Get the current URL var currentUrl = window.location.href; // Define an object with mappings of variables to corresponding text fields var fieldMappings = { utm_campaign: 'mx_utm_campaign', utm_medium: 'mx_utm_medium', utm_source: 'mx_utm_source', }; // Loop through the mappings and insert the values into the corresponding text fields for (var param in fieldMappings) { var fieldName = fieldMappings[param]; var match = currentUrl.match(new RegExp('[?&]' + param + '=([^&]+)')); if (match) { var paramValue = match[1]; var textField = document.querySelector('input[name="' + fieldName + '"]'); if (textField) { textField.value = paramValue; } } }