.submit()返回false导致奇怪的(对我而言)行为

What I'm trying to get is to count which checkboxes in article list are selected, and I'm writing selected to "toDel" jquery variable.

Then, if "toDel" remains empty, I'd like to stop submiting the form, and if there is any, I'm proceeding by adding "toDel" value to hidden field value.

If selected it all works fine, but once if I click button and no chechboxes are selected, "return false" somehow stops, and I when new checkbox is selected, I can't get into "correct" part of the code.

I've checked here, and figured out that I can't use "return false" so I tried with validator variable, but it behaves the same.

    $(document).ready(function(){
$("#jqdeleteselected").on("click", function(){
  var toDel='';
      $('.jqchkbx').each(function() {
         if ($(this).attr('checked')) {
          toDel += ($(this).attr('value')+',')
         }
    });
    console.log(toDel);

    $("#send").submit(function() {
        var valid = true;
        if (toDel != '') {

        $('#boxevi').val(toDel);        
        console.log('filled');

        }
        console.log('empty');
        valid = false;


    });         
    return valid;
});

});

<form method="POST" action='.$_SERVER['REQUEST_URI'].' name="send" id="send">
<input type="hidden" id="boxevi" name="boxevi" />
<input type="submit" id="jqdeleteselected" value="Obriši označene">
<input type="submit" name="addnew" value="Dodaj novi artikl" /></form><br /></div>';

You only need to handle submit event:

$(document).ready(function(){

    $("#send").submit(function() {
        var toDel='';
          $('.jqchkbx').each(function() {
             if ($(this).attr('checked')) {
              toDel += ($(this).attr('value')+',')
             }
        });
        console.log(toDel);

        if (toDel != '') {
            $('#boxevi').val(toDel);        
            console.log('filled');
        }else{
            console.log('empty');
            return false;
        }
    });

});

You only need to handle submit and you can use :checked selector to speed up your check

$(document).ready(function(){
    $("#send").submit(function() {
        var toDel='',
            $this = $(this),
            checkd = $(".jqchkbx:checked");
        checkd.each(function() {
            toDel += $(this).val() + ',';
        });
        console.log(toDel);

        if (checkd.length > 0) {
            $('#boxevi').val(toDel);        
            console.log('filled');
        }else{
            console.log('empty');
            return false;
        }
    });

});