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?

REDGROUP
  • 49
  • 3
  • 1
    Does this answer your question? [How can I check if a checkbox is checked?](https://stackoverflow.com/questions/9887360/how-can-i-check-if-a-checkbox-is-checked) `console.log(document.getElementById('accept').checked)` – ikiK Jun 02 '21 at 22:59
  • With this If I do not check the box, then I get "false" and "true" if is checked – REDGROUP Jun 02 '21 at 23:02
  • Yes? That whats it suppose to do... – ikiK Jun 02 '21 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 ( – REDGROUP Jun 02 '21 at 23:06
  • https://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. – ikiK Jun 02 '21 at 23:07
  • I feel like an idiot, I tried it from the link above and from the documentation, but for some reason the checkbox validation does not work. Although everything else works – REDGROUP Jun 03 '21 at 00:11
  • You need to make [mre] here in snippet. – ikiK Jun 03 '21 at 00:14
  • Your brackets are not properly closed: remove the last one, add another after `required: true`. – msg Jun 03 '21 at 00:52
  • I still have a lot of checks there and everything seems to work. And there are no errors in the console about parentheses. – REDGROUP Jun 03 '21 at 09:24

0 Answers0