Wix Location To Returns "Unsupported URL" Error

Hello! I’m trying to allow users to enter their zip code and have the page forward them to the dynamic page about that zipcode when they click a button.

I’ve created dynamic pages in my southwest zip codes database. I have a column which I have set to URL that is displaying just the unique URL of the dynamic page (e.g. “/southwest/84001”).

I get a Wix Code SDK error that “URL is unsupported”. Help!

import wixData from “wix-data”
import wixLocation from “wix-location”

export function button1_click(event, $w) {
wixData.query(“southwest”)
.contains(“zipCodes”, $w(“#search”).value)
.find()
.then( (southwest) => {
let zipCode = southwest.zipcode
let URL = southwest.url
})
}
$w.onReady( function () {
wixLocation.to(“southwest.url”)
})

1 Like

Hello

I can see the problem to be in this line :

 wixLocation.to("southwest.url") 

It should be written this way without the quotation marks:

 wixLocation.to(southwest.url) 

Best
Massa

Thanks, Massa! When I remove the quotation marks, I get the error that “southwest isn’t defined.”

Yeah that’s because you have it defined in the on click function and not the on ready. You have to define it again inside the on ready or make it a global variable.

Massa

Hmm ok I added it under the OnReady but it still didn’t work. Instead of linking to the field in the database, can I just use the dynamic page structure logic to create the link? My page structure is /southwest/zipcode. I tried the below and I got an error saying the page was undefined.

Thank you!

import wixData from “wix-data”
import wixLocation from “wix-location”

export function button1_click(event, $w) {
wixData.query(“southwest”)
.contains(“zipCodes”, $w(“#search”).value)
.find()
.then( (southwest) => {
let zipcode = southwest.zipcode
})
}
$w.onReady( function () {
wixData.query(“southwest”)
.contains(“zipCodes”, $w(“#search”).value)
.find()
.then( (southwest) => {
let zipcode = southwest.zipcode
wixLocation.to(“/southwest/”+southwest.zipcode)
})
})

Hello
what page you are at and what is the button element id?

Hi, I’m at “Utah Growing Zones” and the button element is button1

@thrive

First thing you need to do is make sure the on click event on the properties panel has the same name as the code. It should look like this:

Second, to link to the dynamic page of the zip code entered all you need to do is use wix location to the link inside the on click function, here how it should look like:

import wixData from "wix-data"
import wixLocation from "wix-location"

export function button1_click(event, $w) {
    wixLocation.to("/southwest/"+$w("#search").value)
}

It should work perfectly now :slight_smile:

Best
Massa

Oh my gosh, thank you, so much! Massa for President!