So right now you switched back to dropdowns?
I am confused…
Thank you for the quick reply. First, i meant radio buttons, not sure why i typed Drop Down
But you use DropDown again.
Ok, let’S say you choose the DropDown-way.
You surely will have a DATABASE, where you have located all the informations in.
Now, how to fill/populate the DropDown with the right DATA ?
Let’s say your DATABASE-ID is —> “myDatabase”
And you store all the informations in a separate DATAFIELD -->ID = “myDatafield”
Now you have created a DropDown onto your page.
Navigate to the code-section of the selected page and put in the following code…
import wixData from 'wix-data';
//-------- USER-INTERFACE -------------------------------------------------
var DBFIELDS = []
var txtFieldID = "#text1" // <--setting Textfield-ID here...
var DD_ID1 = "#DD1" // <--setting Dropdown-ID here...(1st. dropdown)
//var DD_ID2 = "#DD2" // <--setting Dropdown-ID here...(2nd. dropdown)
var DATABASE = "YourCollectionIDhere" // <--setting DATABASE-ID here...
var DBLIMIT = 1000 // <--setting DATABASE-Limit (max.1000)...
var DBFIELDS[0] = "YourDBFieldID1_here" // <--setting DATABASE-Field-ID (1st. DB-Field)
//var DBFIELDS[1] = "YourDBFieldID2_here" // <--setting DATABASE-Field-ID (2nd. DB-Field)
//-------- USER-INTERFACE -------------------------------------------------
$w.onReady(()=>{
//Create-Unique-Dropdown-------------
wixData.query(DATABASE)
.limit(DBLIMIT)
.find()
.then(results=> {
create_UniqueDropdown1(results.items);
create_UniqueDropdown2(results.items);
});
});
//---First ACTIVATED-Dropdown...
function create_UniqueDropdown1(items) {
const uniqueTitles1 = getUniqueTitles1(items);
$w(DD_ID1).options = buildOptions1(uniqueTitles1);
function getUniqueTitles1(items) {
const titlesOnly = items.map(item => item[DBFIELDS[0]]);
return [...new Set(titlesOnly)];
}
function buildOptions1(uniqueList1) {
return uniqueList1.map(curr => {
return {label:curr, value:curr};
});
}
}
//---Second DEACTIVATED-Dropdown...
/*
function create_UniqueDropdown2(items) {
const uniqueTitles2 = getUniqueTitles2(items);
$w(DD_ID2).options = buildOptions2(uniqueTitles2);
function getUniqueTitles2(items) {
const titlesOnly = items.map(item => item[DBFIELDS[0]]);
return [...new Set(titlesOnly)];
}
function buildOptions2(uniqueList2) {
return uniqueList2.map(curr => {
return {label:curr, value:curr};
});
}
}
*/
This should fill your dropdown pulling DATA from your settep-up DATABASE (in the User-Interface-Section of this code).
Normaly this forum is NOT a service-place where you can get code for FREE.
But since you are a novice, i want you to know, that it is not that easy as you perhaps expect to code a good working solution, even if you thinking that it should be an easy task.
Ok, your first step is done and your Dropdown should be automaticaly filled with wished DATA out of your DATABASE, when page is READY!
Now your second step would be to code the ACTIONS, when dropdown-values changes…
Just to keep it as most as possible simple & clear…
-Add a new → “text-field” onto your page → standard-ID → “text1”
Add a new code-line in the USER-INTERFACE-SECTION of your code…
var txtFieldID = "#text1"
Expand your code in the → onReady-Code-Section with the following code-line…
$w(DD_ID1).onChange(()=>{$w(txtFieldID).text = $w(DD_ID1).value;});
Now every change on the dropdown → should be shown in the Text-Field!
Good luck and happy coding! 