Jump to content

Autofill Country Field in Form on Index Page

Recommended Posts

Working on this page, and we'd like to auto fill the COUNTRY field with USA because none of our customers live anywhere else.


I have reviewed all other posts on this topic, and have inserted all suggested code to either autofill, hide, or autofill and hide the country field in Design -> Custom CSS.

The code below almost works, but it throws this error:Your form has encountered a problem. Please scroll down to review.Service Address is missing required subfields: Country

Can anyone help? It seems that a lot of people have this problem, but the solutions that work are from 2017 and predate Squarespace's form verification updates.

     Y.on("domready", function(){
     Y.all('input[name="country"]').setAttribute("value", "US");
   .field.country {
      display: none;

Link to comment
  • Replies 1
  • Views 1.7k
  • Created
  • Last Reply

The JavaScript isn't currently installed on this page but if it was, it wouldn't work.

This is because the form has been added as a lightbox form. These aren't loaded until the user clicks the button to launch it, meaning that the code will load with the page, before the form or the country has been added to it. The code therefore can't precomplete the country information.

If the form was directly on the page, it should (in theory) work as long as Ajax is disabled (the code you've used is old and isn't compatible with it)

About me: I'm Paul, a SQSP user for over 18 yrs and a Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL, providing high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji below. Buying a coffee is optional.

Book paid help with domains: Connect a GoDaddy domain. Connect a Squarespace Domain. Domain assistance

Link to comment


This topic is now archived and is closed to further replies.

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.