0

I'm trying to check before submitting the form to see if the user has checked the checkbox. I've read a lot of stackoverflow, but I mostly find options for multiple checkboxes. In my case, I have only one checkbox to check. How can i do this? Now I have done this:

jQuery validation:

rules: {
 accept: {
    required: true
   },
  messages: {
    accept: {
      required: "Check the box is required"
     }
 }
}

HTML Markup: <input class="input__custom" type="checkbox" id="accept" name="accept" value="1" > But it doesn't work, please tell me what am I doing wrong?

9
  • 1
    Does this answer your question? How can I check if a checkbox is checked? console.log(document.getElementById('accept').checked) Commented Jun 2, 2021 at 22:59
  • With this If I do not check the box, then I get "false" and "true" if is checked Commented Jun 2, 2021 at 23:02
  • Yes? That whats it suppose to do... Commented Jun 2, 2021 at 23:03
  • I am using jQuery validation plugin and i think i need to find solution to check with this plugin. I don't really understand how to proceed further ( Commented Jun 2, 2021 at 23:06
  • stackoverflow.com/a/6578106/7158959 same thing as $("#accept").is(':checked') Read other answers also. It would also be helpful for future notice to make a working snippet, you can use <> button in editor here to create one. Commented Jun 2, 2021 at 23:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.