Knockoutjs Clear Selected Value In Combobox August 07, 2022 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); Copy Solution 2: In some cases setting the observable value to null will not work, for example : // This is the array self.timePeriods = ko.observableArray([ new timePeriod("weekly", 7), new timePeriod("fortnightly", 14), new timePeriod("monthly", 30), new timePeriod("half yearly", 180), new timePeriod("yearly", 365) ]); Copy And below is the HTML part: <select data-bind="options: timePeriods, optionsText: function(item) { return item.Name; }, value: selectedPeriod" class="combo"> Copy You can't reset select box by: self.selectedPeriod(null); // but this will not work Copy Insetead write this: self.selectedPeriod(self.timePeriods()[0]); Copy Solution 3: <script> var vm ={ CountryId=ko.observable(), QC=ko.observable(), clearSelectedStation: function () { this.CountryId(null); //DropDown this.QC(''); //Textbox } }; </script> Copy here 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"