Autofill the Country in Address Form Field

If you hide the Country form field on a Squarespace form block using CSS, you’ll get an error when you try to submit it because the country is a required field. What if you know that your clients will likely always be in the same country? Unfortunately, you can’t make the country field optional, but you can use the code below to auto-populate this field to fill in your desired country.

This also works on custom product forms.

Put the code below into Settings -> Advanced -> Code Injection.

<script>
function populateCountry() {
  var field = document.querySelector('.field.country .field-element');
  if (field) {
    field.value = 'United States';
  } else {
    setTimeout(populateCountry, 500);
  }
}
populateCountry();
</script>

Customization:

To change the country, change ‘United States’ to the country of your choice.

Mali King

I’m a Squarespace expert who has designed hundreds of websites over the course of 4+ years! I love working with small businesses and entrepreneurs to create beautiful, functional websites that stand out from their competition and attracts clients.

https://clementinedesign.studio
Previous
Previous

Force Mobile Navigation on Desktop (7.1)

Next
Next

Make All Accordion Divider Lines the Same Height