/********************************************************
* 5) EDUCATION LEVEL VISIBILITY (HS vs Higher Ed Year)
********************************************************/
const field908771 = document.getElementById('custom-908771'); // Highest Education
const field913213 = document.getElementById('custom-913213'); // HS Year
const field913216 = document.getElementById('custom-913216'); // Higher Ed Year
if (field908771 && field913213 && field913216) {
const row913213 = field913213.closest('.vbfs-row');
const row913216 = field913216.closest('.vbfs-row');
function updateFieldsVisibility() {
const val = field908771.value.trim();
// Remove required by default
field913213.removeAttribute('required');
field913216.removeAttribute('required');
if (val === 'Current High School Junior or younger' || val === 'Current High School Senior') {
row913213.style.display = 'block';
row913216.style.display = 'none';
field913213.setAttribute('required', 'required');
} else if (
val === 'High School Graduate/GED' ||
val === 'Associate Degree' ||
val === "Bachelor's Degree" ||
val === "Master's Degree or higher"
) {
row913213.style.display = 'none';
row913216.style.display = 'block';
field913216.setAttribute('required', 'required');
} else {
// Hide both
row913213.style.display = 'none';
row913216.style.display = 'none';
}
}
field908771.addEventListener('change', updateFieldsVisibility);
field913213.addEventListener('change', updateFieldsVisibility);
field913216.addEventListener('change', updateFieldsVisibility);
updateFieldsVisibility();
}
/********************************************************
* 6) UTM/URL PARAM CAPTURE
********************************************************/
function getQueryParam(param) {
return new URLSearchParams(window.location.search).get(param);
}
const mainForm = document.querySelector('form');
if (mainForm) {
const params = [
{ params: ['utm_source', 'source'], fieldId: '944901' },
{ params: ['utm_keyword', 'keyword'], fieldId: '944902' },
{ params: ['utm_campaignid', 'campaignid'], fieldId: '944903' },
{ params: ['gad_source', 'gadsource'], fieldId: '944904' },
{ params: ['gclid'], fieldId: '944905' },
// For 'landingpage', use the current host + path
{ fieldId: '947483', value: window.location.host + window.location.pathname }
];
params.forEach(function(item) {
let value;
if (item.value !== undefined) {
value = item.value;
} else if (Array.isArray(item.params)) {
for (let p of item.params) {
value = getQueryParam(p);
if (value) break;
}
} else if (item.param) {
value = getQueryParam(item.param);
}
if (value) {
let hiddenField = mainForm.querySelector(
'input[name="vbout_EmbedForm[field][' + item.fieldId + ']"]'
);
if (!hiddenField) {
hiddenField = document.createElement('input');
hiddenField.type = 'hidden';
hiddenField.name = 'vbout_EmbedForm[field][' + item.fieldId + ']';
hiddenField.id = 'custom-' + item.fieldId;
mainForm.appendChild(hiddenField);
}
hiddenField.value = value;
}
});
}
});