First name:
Last name:
Full name:
<p>First name: <input data-bind="value: firstName" type="text" /></p> <p>Last name: <input data-bind="value: lastName" type="text" /></p> <p>Full name: <span data-bind="text: fullName" ></span></p> <script> var viewModel = { firstName: ko.observable("Bert"), lastName: ko.observable("Smith") }; viewModel.fullName = ko.computed( function () { return this.firstName() + " " + this.lastName(); }, viewModel ); ko.applyBindings(viewModel); </script> <script> function KOviewModel () { /* Or: var KOviewModel = function () */ var self = this; self.firstName = ko.observable("Bert"); self.lastName = ko.observable("Smith"); self.fullName = ko.computed( function () { return this.firstName() + " " + this.lastName(); }, this ); }; var viewModel = new KOviewModel(); ko.applyBindings(viewModel); </script>