How to make a button not to submit without checking checkbox and display a validation message

Using jQuery and taegeting form id, button id and checkbox id we can make a button not to submit

Create required html elements with ids

JQuery code is added below


                $(document).ready(function () {

                  $("Form id").on("submit", function (form) {
                    form.preventDefault();
                  $('button id').click(function (e) {  //if button id not available so use data type

                    if (!$("check box").prop("checked")) {// check box id
                      e.preventDefault();
                      $("error message id").show();// error message id
                    }
                    else {
                      $("error message id").hide();
                    }
                    return false;
                  });
                });
              });

Leave a comment

Your email address will not be published. Required fields are marked *