Hi there,
For some reason, my conditional logic coding randomly stopped working a couple of weeks ago.
I am attempting to do the same idea as this thread:
Within the How did you hear about us? field, if a user selects the "Referral" radio button, a Name (first and last), should appear. If a user selects "Other", then a field "Specify" a text field appears.
Again this was working up until a month ago or so (the client believes).
I've attempted a couple of different fixes and code changes, and I've successfully hidden the fields, but now cannot get the conditional logic to fire.
Hoping for some help from the Squarespace crew!
Webpage: https://www.leanagilesensei.com/contact
In the Code Injection section of the site, I have:
In HEADER:
<style>
#name-yui_3_17_2_1_1600810502501_7975,
#text-yui_3_17_2_1_1603146836044_49833 {
display: none;
}
</style>
FOOTER:
<script
(function(){
// The value of the "id" HTML attribute of the parent HTML element
var PARENT_ID = 'radio-yui_3_17_2_1_1603146836044_50638';
// The value which will determine the visibility of the DEPENDENT_ID element
var PARENT_VALUE = ['Referral', 'Other'];
// The value of the "id" HTML attribute of the child HTML element.
// This field will hide/show depending on the PARENT_VALUE
var DEPENDENT_IDS = [
'name-yui_3_17_2_1_1600810502501_7975',
'text-yui_3_17_2_1_1603146836044_49833'
];
/*********************************************************************
* DO NOT ALTER BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING
*********************************************************************/
// Initialize after the page has been loaded
if (document.readyState === 'complete') {
init();
} else {
document.addEventListener("DOMContentLoaded", init, false);
}
function init() {
// Load jQuery if not loaded
if(!window.jQuery) { return loadJquery(init) }
// Assign jQuery to a variable
var $ = jQuery;
// Get the parent element
var $parentField = $('#' + PARENT_ID);
// Create ID CSS selectors based on the DEPENDENT_ID.
var ids = DEPENDENT_IDS.map(id => '#' + id);
ids.forEach(id => {
// Get the dependent element
var $dependentField = $(id);
// Hide the text field on page load
$dependentField.hide();
});
// Show or hide the dependent field based on the PARENT_VALUE
$parentField.on('change', function(evt){
if(PARENT_VALUE.includes(evt.target.value)) {
$(ids.join(',')).slideDown();
} else {
$(ids.join(',')).slideUp();
}
});
}
function loadJquery(init) {
var s = document.createElement('script');
s.src = 'https://code.jquery.com/jquery-3.6.0.min.js';
s.integrity = 'sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=';
s.crossorigin = 'anonymous';
s.onload = init;
document.body.appendChild(s);
};
})();
</script>