How to add code to filter database by two specific criteria

I currently have code (Find Below) that works great filtering out duplicate entries for a dropdown box. The code filters out the duplicates of a dropdown box but I noticed that it shows all items in the database rather than showing just specific entries. What approach could I take to amend my current code to continue filtering duplicates but only show items from a specific criteria.

For example Users login and are directed to a form. Form contains a dropdown of registration numbers which user can choose from. Form also has a second dropdown which shows another field in the database. But second dropdown should only show information for items associated with first dropdown selection (registration). (minus duplicates - code filters out)

My question would be what can I add to current code to allow second dropdown to continue to show the same field from the database but only show the information that’s associated with the registration dropdown. Visual Below. Thanks for your help

Registration Name

0001 ABC
0004 DAD
0010 KAT
0001 RUN

Procedure

  1. First Dropdown (Registration) user selects 0001
  2. Second Dropdown (Name) should only show Names Associated with 0001 (ABC, RUN)

Current Code “as is” for 2nd dropdown shows - ABC, DAD, KAT, RUN

Current Code
import wixData from 'wix-data';
$w.onReady(function () {
	wixData.query("TournamentRegistration")
		.limit(1000)       
 		.find()
 		.then(results => {
		  	const uniquexboxgamertag = getUniquexboxgamertag(results.items);   
		  	$w("#xboxdropdown").options = buildOptions(uniquexboxgamertag);    
 		});
 	function getUniquexboxgamertag(items) {  
   		const xboxgamertagOnly = items.map(item => item.xboxGamerTag);   
      		return [...new Set(xboxgamertagOnly)];
	}
	function buildOptions(uniqueList) {   
		return uniqueList.map (curr => {
			return {label:curr, value:curr};  
		});
	}
});

Thank Again For Your Help

Hi Darnell,

In order to update the second dropdown according to the selection of the first dropdown, you can use the onChange event on the dropdown.

You can extract the selected value, and build the options of the second dropdown according to it.

You can find more information about the event here: Dropdown - Velo API Reference - Wix.com.

Good luck,
Idan.