How to pre-select an option in a dropdown knockout js

http://stackoverflow.com/questions/8449824/how-to-pre-select-an-option-in-a-dropdown-knockout-js

by neosketo

HTML

<select data-bind="options: States, optionsText: 'text', value: SelectedState"></select>

JavaScript

//when user is logged in we get users State. Default is null
var usersState = 9


function ViewModel() {
   this.States = ko.observableArray(states);
   this.SelectedState = ko.observable(usersState); 
};


var states = [
        { value: 10, text: "California" },
        { value: 3, text: "New York" },
        { value: 9, text: "Florida" }
    ];




ko.applyBindings(new ViewModel());