Knockoutjs Clear Selected Value In Combobox November 28, 2023 Post a Comment I have this simple knockout.js application: View: Solution 1: You must change binding type to "value" instead of "selectedOptions". Next step is to set viewModel.selectedDocument in cl function:viewModel.selectedDocument(null); CopySolution 2: In some cases setting the observable value to null will not work, for example :// This is the arrayself.timePeriods = ko.observableArray([ new timePeriod("weekly", 7), new timePeriod("fortnightly", 14), new timePeriod("monthly", 30), new timePeriod("half yearly", 180), new timePeriod("yearly", 365) ]); CopyAnd below is the HTML part:<select data-bind="options: timePeriods, optionsText: function(item) { return item.Name; }, value: selectedPeriod" class="combo"> CopyYou can't reset select box by: self.selectedPeriod(null); // but this will not workCopyInsetead write this:self.selectedPeriod(self.timePeriods()[0]); CopySolution 3: <script>var vm ={ CountryId=ko.observable(), QC=ko.observable(), clearSelectedStation: function () { this.CountryId(null); //DropDownthis.QC(''); //Textbox } }; </script>Copyhere is a html <input type="text" tabindex="10"data-bind="value:QC"/> <select class="dropdownlist" data-bind="options:Countries, value: CountryId, optionsCaption: '--Select--', optionsText: 'CountryName', optionsValue: 'CountryId'">Copy Share Post a Comment for "Knockoutjs Clear Selected Value In Combobox"
Post a Comment for "Knockoutjs Clear Selected Value In Combobox"