JSFiddle - React, Tailwind, and code Playground
HTML
<input data-bind="checked: selectedValues" type="checkbox" value="500">500</input>
<input data-bind="checked: selectedValues" type="checkbox" value="200">200</input>
<input data-bind="checked: selectedValues" type="checkbox" value="100">100</input>
<br/>
Result:
<input data-bind="value: sum" type="text"></input>
JavaScript
function ViewModel() {
var self = this;
self.primaryClass = ko.observable("50");
self.secondaryClass = ko.observable("40");
self.otherClass = ko.observable("10");
self.selectedValues = ko.observableArray([]);
self.sum = ko.computed(function () {
var total = 0;
ko.utils.arrayForEach(self.selectedValues(), function (item) {
total += parseInt(item);
});
return total;
});
}
ko.applyBindings(new ViewModel());