mercredi 9 septembre 2020

Multiple checkboxes state checked

I am using knockout Js. There are two checkboxes. If any checkbox is not checked then the submit button will be disabled. There might be cases where there will be 1 checkbox instead of 2 checkboxes. So I have a condition like this

 if ((self.checkBox1() === true && self.checkBox2() === true) || ($("#checkbox2").length <= 0 && self.checkBox1() === true) || ($("#checkbox1").length <= 0 && self.checkBox2() === true)) {
        $('.submit-btn').attr('disabled', false);

    } else {
        $('.submit-btn').attr('disabled', true);

    }
    return true;
}

This is a Jsfiddle sample I have created.

Is there a better way of doing this?




Aucun commentaire:

Enregistrer un commentaire