Hi Everyone!
I have been in trouble for a long time, I am very thankful that you will help me.
I have created two dropdowns. In which the first one is { "#cityNameDropdown" } which is connected to the { "#dataset5" "Delivery Cities" } contains multiple cities which redirects to dynamic pages when clicked except Delhi city.
And the other one is { "#cityLocationDropdown" } which is connected to the { "#dataset4" "Delhi" } .disable on load, .onChange with { "#cityNameDropdown" } .enable only when city Delhi is clicked and having Delhi's multiple locations which redirects to their dynamic pages. Both are working well.
My query is that there is a text element on my website Header, which I have named Choose City and whose ID is { "#deliveryCityText" }. I want that whichever city is selected except Delhi from the { "#cityNameDropdown" } or if Delhi is the city selected than whichever Delhi's location is selected from the { "#cityLocationDropdown" }, it's value displays in { "#deliveryCityText" } even after changing every page, it should not be changed until it is changed back from dropdown.
For example, you can check some other web by visiting cake24x7 with extension .com
Because I do not know much of coding, please tell the code by giving a little detail with example if possible.
I have written this code by reading several wix articles but all are not working in my { "#deliveryCityText" }.
import wixLocation from 'wix-location';
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query("Delhi")
.limit(100)
.ascending("title1")
.distinct("title1")
.then(r => {
let options = r.items;
options = options.map(e => { return { label: e, value: e }; });
$w("#cityLocationDropdown").options = options;
});
});
export function cityLocationDropdown_change(event) {
$w("#dataset4").setCurrentItemIndex(event.target.selectedIndex)
.then(() => {
wixLocation.to($w("#dataset4").getCurrentItem().title2);
});
}
$w.onReady(function () {
$w('#cityLocationDropdown').options;
$w('#cityLocationDropdown').disable();
$w('#cityNameDropdown').onChange(() => {
if ($w('#cityNameDropdown').value === 'Delhi') {
$w('#cityLocationDropdown').options;
$w('#cityLocationDropdown').enable();
} else {
$w('#cityLocationDropdown').value = '';
$w('#cityLocationDropdown').disable();
}
});
});
export function cityNameDropdown_change(event) {
$w("#dataset5").setCurrentItemIndex(event.target.selectedIndex)
.then(() => {
wixLocation.to($w("#dataset5").getCurrentItem().titleLink);
});
}
$w.onReady(function () {
wixData.query("Delivery Cities")
.eq("titleMain", $w('#cityNameDropdown').value)
.find()
.then((results) => {
$w('#deliveryCityText').text = results.items[0].value;
console.log(results.items);
})
.catch((err) => {
let errorMsg = err;
});
});
@Yisrael (Wix)
Hi
Thanks for your reply!
Your are right that by copying and pasting code you cannot do any work and especially a good job.
As I mentioned above, I am new to Wix and don't even know much coding, had heard that Wix is a good and easy platform and that's why I decided to create my website in it first.
If this forum is a community of great and professionals Corvid developers like you, Can you help and guide where newcomers go and practically discuss their problems to increase their knowledge?
I have taken a lot of knowledge from Wix articles, tutorials and community and have also completed a lot of work on my project. Just got stuck on a code. It will take some time to become as great and professional as you. It may have taken you a while to reach here.
Anyway, again thanks for your reply and above mentioned guidence.
Please realize that you can't just "copy and paste" code and expect it to work. You need to understand what's happening if you expect to be able to write code that does what you want.
This forum is a community of Corvid developers and users where various topics are discussed and information shared. It is not a support site and not a place to expect a full code solution. You will need to familiarize yourself with basic coding concepts to accomplish what you want. We are happy to get you pointed in the right direction and get you started with what the code should look like, but you’ll need to take it from there.
To learn about programming with Corvid, read the following articles that will help you start working with Corvid:
About Corvid by Wix - what Corvid is and what features it has.
Getting Started with Corvid by Wix - step-by-step tutorial on how to start using Corvid.
Onboarding to Corvid by Wix - introduction to Corvid with short tutorials.
If you find that you are having difficulty with code and need assistance, you may want to check out the Wix Marketplace - it's a place where you can look for Corvid experts for hire.