I am using a dropdown box to allow users to be redirected to different URLS based on the option they select.
This feature used to work but now it does not, the code I have written is below, any idea why this is not working?
Any help appreciated, thanks
import wixLocation from 'wix-location'; $w.onReady(function () { $w("#dropdown1").options = [ {"label": "View All Sports", "value": "URL"}, ]; }); export function dropdown1_change(event) { let gotoUrl = $w("#dropdown1").value; wixLocation.to(gotoUrl); }
Refer to the wixLocation.to() function and query parameters. To get user input, see TextInput.
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.
To learn about Javascript programming:
https://www.w3schools.com/js/default.asp
https://javascript.info
Wix is unable to support a search of a 3rd party site. If you wish to redirect, you can use the wixLocation.to() function with query parameters.
@GOS / AV Digital,
I didnt get anywhere with this. I am going to try and take a different approach (and probably better if it is possible)
Essentially I am trying to search a marketplace of mine on a third party site. This has a search feature. Is there a way to create a search that when a user has typed the keywords they are looking for it directs them there.
For example, on wix I have a user input box, or search box, the user types 'Football' This then takes me to the URL+' KEYWORD USER TYPED, IN THIS EXAMPLE ITS FOOTBALL'
The base URL is always the same, Do you know if this is possible?
Just added that options list to test site and it all runs fine on this page.
https://givemeawhisky.wixsite.com/sportsattictest/owncode
import wixLocation from 'wix-location'; $w.onReady(function () { $w("#myDropdown").options = [ { "label": "View All Sports", "value": "https://shop.sportsattic.co.uk" }, { "label": "American Football", "value": "https://shop.sportsattic.co.uk/?category=american-football" }, { "label": "Archery", "value": "https://shop.sportsattic.co.uk/?category=archery" }, { "label": "Accessories", "value": "https://shop.sportsattic.co.uk/?category=accessories" }, { "label": "Basketball", "value": "https://shop.sportsattic.co.uk/?category=basketball" }, { "label": "Bikes", "value": "https://shop.sportsattic.co.uk/?category=bikes" }, { "label": "Boxing", "value": "https://shop.sportsattic.co.uk/?category=boxing" }, { "label": "Boating/Kayaking", "value": "https://shop.sportsattic.co.uk/?category=boating-slash-kayaking" }, { "label": "Climbing", "value": "https://shop.sportsattic.co.uk/?category=climbing" }, { "label": "Crossfit", "value": "https://shop.sportsattic.co.uk/?category=crossfit" }, { "label": "Cricket", "value": "https://shop.sportsattic.co.uk/?category=cricket" }, { "label": "Dance", "value": "https://shop.sportsattic.co.uk/?category=dance" }, { "label": "Darts", "value": "https://shop.sportsattic.co.uk/?category=darts" }, { "label": "Football", "value": "https://shop.sportsattic.co.uk/?category=football" }, { "label": "Fishing", "value": "https://shop.sportsattic.co.uk/?category=fishing" }, { "label": "Golf", "value": "https://shop.sportsattic.co.uk/?category=golf" }, { "label": "Gym Equipment", "value": "https://shop.sportsattic.co.uk/?category=gym-equipment-weights-machines-etc" }, { "label": "Hiking/Camping", "value": "https://shop.sportsattic.co.uk/?category=hiking-slash-camping" }, { "label": "Hockey (Field)", "value": "https://shop.sportsattic.co.uk/?category=hockey-field" }, { "label": "Hockey (Ice)", "value": "https://shop.sportsattic.co.uk/?category=hockey-ice" }, { "label": "Horse Riding", "value": "https://shop.sportsattic.co.uk/?category=horse-riding" }, { "label": "Judo/Karate", "value": "https://shop.sportsattic.co.uk/?category=judo-slash-karate" }, { "label": "Lacrosse", "value": "https://shop.sportsattic.co.uk/?category=lacrosse" }, { "label": "MMA", "value": "https://shop.sportsattic.co.uk/?category=mma" }, { "label": "Netball", "value": "https://shop.sportsattic.co.uk/?category=netball" }, { "label": "Running", "value": "https://shop.sportsattic.co.uk/?category=running" }, { "label": "Rugby", "value": "https://shop.sportsattic.co.uk/?category=rugby" }, { "label": "Skiing/Snowboarding", "value": "https://shop.sportsattic.co.uk/?category=skiing-slash-snowboarding" }, { "label": "Snooker/Pool", "value": "https://shop.sportsattic.co.uk/?category=snooker-slash-pool" }, { "label": "Table Tennis", "value": "https://shop.sportsattic.co.uk/?category=table-tennis" }, { "label": "Tennis/Squash/Badminton", "value": "https://shop.sportsattic.co.uk/?category=tennis-slash-squash-slash-badminton" }, { "label": "Volleyball", "value": "https://shop.sportsattic.co.uk/?category=volleyball" }, { "label": "Wrestling", "value": "https://shop.sportsattic.co.uk/?category=wrestling" }, { "label": "Other Sports", "value": "https://shop.sportsattic.co.uk/?category=other-sports" } ]; }); export function myDropdown_change(event) { let url = $w('#myDropdown').value; wixLocation.to(url); }
@GOS @AV, I am in preview just to show you the code. Feel free to go to the site and test the button it does not work.
@GOS He seems to be using the new X editor, and you are to the old editor. Maybe there is some difference?
However, as you wrote and wrote to him at first, he seems to be trying on the preview rather than the live site.
Check back on the live site.
How is it a bug when it all works fine.
https://givemeawhisky.wixsite.com/sportsattictest
import wixLocation from 'wix-location'; $w.onReady(function () { $w("#myDropdown").options = [ { "label": "View all Sports", "value": "https://www.sportsattic.co.uk" }, { "label": "Wix", "value": "http://wix.com" } ]; }); export function myDropdown_change(event) { let url = $w('#myDropdown').value; wixLocation.to(url); } export function myDropdown1_change(event) { let url = $w('#myDropdown1').value; wixLocation.to(url); }
I set the value using the code
Have a look at Nayeli (Code Queen) tutorial about it here.
Use dropdowns to navigate to another page on Wix - 8 lines of Code
https://www.totallycodable.com/example-dropdown-navigation
https://www.totallycodable.com/wix/corvid/use-dropdowns-to-navigate-to-a-different-page
For your code with the url added to the value for the dropdown itself, then you are best using Nayeli's last chunk of code for manual settings.
import wixLocation from 'wix-location'; $w.onReady(function () { $w("#dropdownManual").onChange((event) => { let url = $w('#dropdownManual').value; wixLocation.to(url); }); });
You might try to set dropdown1 manually without code.
Anyway you might want to include screenshots
You may want to check this code to find out where the problem is.
Maybe there is only one value so don't see a change in value, so check if it prints 'change'
And maybe the address is wrong so try it.
import wixLocation from'wix-location'; $w.onReady(function () {$w("#dropdown1").options = [ {"label": "View All Sports", "value": "https://www.google.co.il/"},];}); exportfunction dropdown1_change(event) { console.log("Change"); let gotoUrl = $w("#dropdown1").value; wixLocation.to(gotoUrl); }
Have you checked it out on the live site?