Add a car make and model dropdown to Squarespace
Where the picker goes on a Squarespace page, which plans run it, and how to collect the vehicle someone picks.
On Squarespace the picker goes in a Code Block. Two things decide how far you get: your plan, because JavaScript in a code block needs one of the plans Squarespace names below, and your form, because Squarespace's own Form Block only sends the fields it creates.
What you get
A make select, a model select that fills when someone picks a make, and a year select, from the official vehicle registers behind the VehiclesDB dataset. Cars by default; motorcycles, vans and trucks are an option.
The block
Paste where the vehicle fields go
<label for="vehicle-make">Make</label>
<select id="vehicle-make" name="make"></select>
<label for="vehicle-model">Model</label>
<select id="vehicle-model" name="model"></select>
<label for="vehicle-year">Year</label>
<select id="vehicle-year" name="year"></select>
<script src="https://cdn.jsdelivr.net/npm/make-model-dropdown@0.4.1"></script>
<script>
VehiclesDropdown.attach({
make: "#vehicle-make",
model: "#vehicle-model",
year: "#vehicle-year",
kind: "car",
order: "popular",
includeOther: true,
otherLabel: "Other / not listed",
placeholderMake: "Make",
placeholderModel: "Model",
placeholderYear: "Year",
source: "dataset"
})
</script>
This block works as it is, with no key and no account: it reads the open dataset and shows a small credit line under the picker, which free use requires. Paid plans can remove the credit line.
Want another language, vehicle kind or country? Choose your options and copy your own block. A free key adds make logos and puts the most registered makes at the top of the list.
Add it to a page
- Open the page and click Add block (or a + insert point), then choose Code.
- Click the pencil icon on the block to edit it, and set the Mode menu to HTML. In CSS or JavaScript mode, Squarespace shows code as text instead of running it.
- Paste the block and save.
- Check the page in a private window, or click Preview in Safe Mode: Squarespace says code sometimes doesn't appear while you're logged in.
Plans. Squarespace's help center says JavaScript in code blocks is available on the Core, Plus and Advanced plans and some legacy billing plans (at the time of writing). On other plans, a code block takes HTML and CSS but not the script, so the picker never loads.
Collecting the vehicle
Squarespace's Form Block is built from its own field types, and its documentation gives no way to add a field from a code block. A picker sitting next to a Form Block is not sent with it. So the picker needs a form of its own, in the same Code Block:
- Use a form service that accepts ordinary HTML forms (one that gives you an address for your form to send to).
- In the Code Block, write that form with your other fields (name, email, phone) and paste the picker block inside it, before the submit button.
- Submissions then carry fields called
make,modelandyear, with short lowercase values such asvolkswagen,golfand2019.
If you'd rather keep the Form Block, the picker can still sit above it as a helper, but the vehicle won't arrive with the submission.
Check that it works
- Open the published page in a private window.
- Pick a make, a model and a year, fill in the rest and send the form to yourself.
- Look for
make,modelandyearin what your form service received.
The picker is done when that test submission arrives with the vehicle in it, not when the lists appear.
Common problems
- You see the code as text. Set the Code Block's mode to HTML.
- The picker never loads. Your plan may not allow JavaScript in code blocks; see above.
- It doesn't appear while you're logged in. Check in a private window or with Preview in Safe Mode.
- It doesn't render on some pages. Squarespace says custom code might not render on a page inside an index page, or when Ajax loading is on.
-
Nothing loads, and the browser console mentions a Content Security Policy.
Your site sends a policy that blocks scripts from other sites. Allow
https://cdn.jsdelivr.netfor scripts and connections, andhttps://vehiclesdb.comfor connections if your block has a key. -
You use a block with a key.
A key only works on the websites it is locked to. Keys made on the
embed page are locked to your site and also work on your own computer
(
localhost) for testing. To test on a staging or preview address, add it to the key's websites in Settings first.
Every other guide, from WordPress to Shopify, is on the make and model dropdown page.
Questions people ask
Which Squarespace plans can run the picker?
The picker needs JavaScript in a Code Block. Squarespace's help center says that is available on the Core, Plus and Advanced plans and some legacy billing plans.
Can I add the picker to a Squarespace Form Block?
Squarespace's form block is built from its own field types, and its documentation gives no way to add fields from a Code Block, so a picker placed next to a Form Block isn't sent with it.
Why can't I see the picker while I'm logged in?
Squarespace says code in a code block sometimes doesn't appear while you're logged in, even when visitors can see it. Check the page in a private window, or click Preview in Safe Mode.