I would like to know how to get the value of the TEXT selected from the dropdown menu, just remember that my drop down menu has the fixed data and are not populated by a "ko.observableArray ()". Any ideas?
When I select an option want to have: Value and Text selection.
<p>
Select a car:
<select data-bind="value: selectedValue, optionsText:???">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</p>
<span data-bind="text: selectedValue"></span>
<br/>
<span data-bind="text: selectedText"></span>
My ko ViewModel:
var viewModel = {
selectedValue : ko.observable(),
selectedText : ko.observable()
};
ko.applyBindings(viewModel);
See this Fiddle: JSFiddle
You have to work with options binding for this. And like Jeff says, don't misuse.
Markup:
This is the simplest way to do so. For more complicated scenarios visit the docs.
JsFiddle 1, JsFiddle 2