Jquery submit not working?

Want to do something like validation, there is a group input type="checkbox" one of them must stand, i.e. not suitable required.

If initially not to put any checked, then the form works as it should, i.e. not sent, but if immediately after attempting to send, put at least one checked, the form will not sent. If you refresh the page and immediately put at least one checked, the form is submitted. The question, why not the form is submitted after at least one successful attempt?
code structure:

<form id="form">

 <div class="checked_box">
 <input type="checkbox">
 <input type="checkbox">
 <input type="checkbox">
</div>

 <button type="submit" class="btn_submit">Submit form</button>

</form>


$('.btn_submit').click(function() {
 var checked = $('.checked_box').children('input:checkbox:checked').length;
 if(checked == 0) {
$("#form").submit(function(){
 return false;
});
 } else {
$("#form").submit();
}
 });
June 14th 19 at 20:36
2 answers
June 14th 19 at 20:38
print to the console the value of var checked
deduced if no cheked-out is not selected, set to 0 if the marked how marked 1,2,3, and so much value, so compare with 0. - nikita.Stracke commented on June 14th 19 at 20:41
if after the page loads immediately put at least one tick then submit() is triggered, and if none of the checkboxes is not set, it also works correctly, sends nothing, but it will not be sent after that even if you put a tick. - nikita.Stracke commented on June 14th 19 at 20:44
June 14th 19 at 20:40
Again Misha. All..x nya.

Why are you pressing the catch, and then it is not clear what you are doing? While actually the action buttons do not even try to override and stop. There is specially design for forms $('#form').submit(function() {...
when

$(".btn_submit").submit(function(){
 return false;
 });


and

$(".btn_submit").submit();

also tried, the effect is the same. - nikita.Stracke commented on June 14th 19 at 20:43
you need something
$(".btn_submit").click(function(e){
e.preventDefault();
 // Here your code
})
- nikita.Stracke commented on June 14th 19 at 20:46
just said all..x nya. )) really, why to handle the click on the button, if you directly use $('#form').submit(); Thank you! - nikita.Stracke commented on June 14th 19 at 20:49
so too tried, does not work. more precisely he worked in the same way as the above code - Kennith62 commented on June 14th 19 at 20:52

Find more questions by tags jQuery