Add a car make and model dropdown to Wix
Where the picker goes on a Wix site, and the honest answer on getting the vehicle into a Wix form.
Wix keeps embedded code in a box of its own: an iframe, which is a small separate page inside your page. That keeps your site safe from other people's code, and it also decides what the picker can do on Wix. It shows and works inside that box, and Wix's documentation gives it no way to fill a field of a Wix form outside it. This guide shows where it goes and what your options are for collecting the answer.
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
Wix has several editors, and the element has a slightly different path in each. In every case it's the HTML embed element:
- Wix Editor: Add Elements, then Embed Code, then Embed HTML. Add your code to the element and apply it.
- Wix Studio: Add Elements, then Embed & Social, then the iFrame element. Click Embed Code, then Enter Code, paste the block, and click Apply.
- Wix Harmony: + Add, then Elements, More Options and Embed. Drag the Embed code element onto the page and paste the block in its settings.
Then make the element tall enough for the selects and the credit line under them, and publish. Wix displays only HTTPS code and addresses in these elements; the block uses HTTPS throughout.
Getting the vehicle into a form
Here is what Wix's own documentation says, and what follows from it:
- The HTML element runs in a sandboxed iframe that "doesn't have direct access to the other elements on your page". So the picker can't fill or join a Wix Forms form next to it.
- Wix's Custom Code settings are for code that is "always invisible" to visitors, so they're not a home for the picker either.
That leaves two routes, both for whoever builds your site:
- Velo page code. Wix documents messages from an HTML element to the page's code (
postMessagein the element,onMessageon the page). The picker announces each choice with amake-model-dropdown:changeevent, so a few lines inside the element can pass the vehicle on, and the page's code decides what to do with it. - The whole form inside the embed. Put a plain HTML form in the same element, with the picker inside it, sending to a form service that accepts ordinary HTML forms. Wix's documentation doesn't say whether forms inside its embeds may submit, so send a test before you rely on it.
If neither suits you, the picker can still sit on the page as a helper, but the vehicle won't reach your Wix form. Tell us what your form looks like and we'll tell you what we'd do.
Check that it works
- Open the published site in a private window.
- Pick a make, a model and a year.
- If you built one of the routes above, send a test the way a customer would and check that the vehicle arrives where you expect it.
Common problems
- The picker is cut off. Make the embed element taller.
- Nothing shows. Check the published site in a private window, and that you pasted the whole block, script included.
-
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.
Building somewhere else too? Every guide is on the make and model dropdown page.
Questions people ask
Can I put the picker inside a Wix Forms form?
Not directly. Wix shows HTML embeds inside an iframe, a separate frame that has no access to the rest of the page, and Wix's documentation gives no way for an embed's fields to join a Wix form.
Can I use Wix's Custom Code settings instead?
Not for the picker. Wix says code added in Settings, Custom Code, is always invisible to visitors, and that visible code belongs in an embedded HTML element. It also needs a published site with a connected domain.
Is there a way to pass the vehicle to the page?
Yes, for a developer: Wix's Velo lets the page's code receive messages from an HTML element (postMessage and onMessage). What the page does with the vehicle then is up to that code.