In my dropdown list, I have prepopulated a selection of strings. My select list is bound as follows:
<select id="industryDropDown"
data-bind="options: $root.orgIndustrySuggestions, value: $root.selectedIndustryTag, optionsCaption: ''"></select>
Within my viewmodel, I have the following code snippet:
self.selectedIndustryTag.subscribe(function (newValue) {
if (newValue !== '') {
if (newValue !== 'undefined') {
alert(self.selectedIndustryTag());
self.selectedIndustryTag('');
}
}
}, self);
The goal is to retrieve the selected value from the drop-down list, perform an action at the current location of the alert(), and then reset the selected value back to the default empty string option.
Currently, when this code is executed, the initial page load works fine. However, upon selecting an item, it displays the selected value once correctly but then repeats showing 'undefined' multiple times afterward.