Search Matches in one listbox and print the matches in another list box
- June 7, 2023
- 1 reply
- 702 views
Hello! I have the following code, to find matches in a listbox and print it in another listbox, but it doesn't work, I don't know if it's possible to do this.
The script is in the document javascript section:
// Function to search for matches in the ListBox and show them in another ListBox
function findMatches() {
// Get the value of the search text box
var searchText = this.getField("criteria").value.toLowerCase();
// Get the ListBox where the matches will be displayed
var listBoxData = this.getField("listdata");
var listBoxResults = this.getField("listresults");
// Clear the ListBox of results
listBoxResults.clearItems();
// Array to store the matches found
var matches = [ ];
// Loop through the options of the data ListBox
for (var i = 0; i < listBoxData.numItems; i++) {
var option = listBoxData.getItemAt(i);
// Check if the option text partially matches the search
if (option && option.value && option.value.toString().toLowerCase().includes(searchText)) {
// Add the option to the matches array
matches.push(option.value);
}
}
// Add the matches to the ListBox of results
for (var j = 0; j < matches.length; j++) {
listBoxResults.addItem(matches[j]);
}
}
In the button I have the following script to call the function:
searchMatches();
When trying to search for matches it does not return any results, please help me 🙂
