window.onload=function(){ //ViewModel for Knockout JS function ViewModel() { //Get the scope we need by declaring this variable var self = this; //Set up tracking for each of the three permission levels self.amo_exec = ko.observableArray([]); self.amo_read = ko.observableArray([]); self.amo_write = ko.observableArray([]); //Knockout JS - the back end of the databindings //The functions compute what is displayed self.sum_amo_exec = ko.computed(function () { return addcombine(self.amo_exec()); }); self.sum_amo_read = ko.computed(function () { return addcombine(self.amo_read()); }); self.sum_amo_write = ko.computed(function () { return addcombine(self.amo_write()); }); //To avoid repetition, this function is called by the above three functions function addcombine($innerarray){ $innerarray = $innerarray.map(function(item){return parseInt(item)}); var count = 0; for(var i = 0; i < $innerarray.length; i++) { count = count + $innerarray[i]; } return count; } } //A function that dynamically generates the table full of checkboxes function makeTable(){ //Append headline to the table jQuery('#permissions_table').append("