JSFiddle - React, Tailwind, and code Playground
HTML
<p>First name:
<input data-bind="value: firstName,valueUpdate: 'afterkeydown'" />
</p>
<p>Last name:
<input data-bind="value: lastName,valueUpdate: 'afterkeydown'" />
</p>
<p>Full name: <strong data-bind="text: fullName,"></strong>
</p>
<button data-bind="click: capitalizeLastName">Go caps</button>
JavaScript
function AppViewModel() {
var self = this;
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function () {
return self.firstName() + " " + self.lastName();
}, this);
this.capitalizeLastName = function () {
var currentVal = self.lastName(); // Read the current value
self.lastName(currentVal.toUpperCase()); // Write back a modified value
};
}
ko.applyBindings(new AppViewModel());