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”)
})
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.
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)
})
})
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)
}