Click here to Skip to main content
15,943,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
i do have a requirement that to perform an operation when checkbox is clicked using knockout js. In my scenario initially i am displaying 8 lines of design code as same by creating 8 objects to that corresponding entity.
so when ever user enteres 1st line data i need to get those values and placed into remaining 7 lines fields respectively. so for that i have taken one checkbox at the top and when it is clicked i have written corresponding code in the click event of checkbox.
it is working fine but when ever again checked i need to remove the data from all 7 lines where ever the data is present. my code is as follows.

Design Code:-
<input type="checkbox" id="checkboxid" data-bind="click: ApplyToAll,enable: EnableApplyAll" />

In corresponding Model:-

var self = this;
self.chkValue = ko.observable(false);

self.lines = ko.observableArray([new SupplierLine(), new SupplierLine(), new SupplierLine(), new SupplierLine(), new SupplierLine(), new SupplierLine(), new SupplierLine(), new SupplierLine()]);

self.EnableApplyAll = ko.computed(function () {
                var h = self.lines()[0].Height();
                var l = self.lines()[0].Length();
                return h != "" && l != "";

self.ApplyToAll = function () {
if (self.chkValue()) {
var h;
var l;
var t;
var m;
$.each(self.lines(), function (ind, ln) {
if (ind == 0) {
h = ln.Height();
l = ln.Length();
t = ln.strThick();
m = ln.strUnits();

else if (ind != 0) {


if (ind == 7) {
else {
$.each(self.lines(), function (ind, ln) {
if (ind != 0) {


but when ever again checked it is not coming into else part, and the data is not removing. please help me to solve this, or did i write any mistake in my code, plz let me know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900