momo2000 Posted July 22, 2023 Share Posted July 22, 2023 Since May 2020, I had used the code below in "Code Injection" to default the State and Country fields, and then hide the Country fields for all of the forms on my site. But it seems that Squarespace had an update a few months ago that broke this. I'd like to know what I can do (code changes) to get that functionality back. Below is the code I used and source. <!--added by MOAKES 5/24/20 from https://forum.squarespace.com/topic/141931-autofill-country-field-in-form-on-index-page/#comment-183491 --> <script> Y.on("domready", function(){ Y.all('input[name="state"]').setAttribute("value", "GA"); Y.all('input[name="country"]').setAttribute("value", "USA"); }); </script> <style> .field.country { display: none; } </style> <!-- End MOAKES --> Link to comment
momo2000 Posted July 22, 2023 Author Share Posted July 22, 2023 One of the forms on the site is here: https://fullyfurnishedministries.org/donate-furniture1 Link to comment
tuanphan Posted July 24, 2023 Share Posted July 24, 2023 For these fields? Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
SeptemberDesign Posted December 13, 2023 Share Posted December 13, 2023 Yes I am interested in this too, removing the country and making the state default to CA Link to comment
AlexSan Posted December 13, 2023 Share Posted December 13, 2023 @momo2000, Not sure if you ever got this fixed, but would this work? <script> document.addEventListener("DOMContentLoaded", function () { // Set default value for the state input based on aria-label var stateInput = document.querySelector('input[aria-label="State"]'); if (stateInput) { stateInput.value = "GA"; } // Set default value for the country select based on aria-label var countrySelect = document.querySelector('select[aria-label="Country"]'); if (countrySelect) { countrySelect.value = "USA"; } }); </script> <style> .field.country { display: none; } </style> @SeptemberDesign, this might not work for you as your site could be set up differently. Link to comment
E-W Posted March 14 Share Posted March 14 Having issues with this too. Anyone figured something out? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment