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.

https://www.americanwastemi.com/paperless

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.


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




Link to comment
  • Replies 1
  • 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)

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment

Archived

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.