How to get the values of all checked checkboxes using jQuery

前端 未结 6 1915
傲寒
傲寒 2020-12-15 11:45

I don\'t know how to pass the selected values of the checkboxes. Any help or suggestions will be a big help for me.

As of now here is my code I am stuck in passing th

6条回答
  •  爱一瞬间的悲伤
    2020-12-15 12:19

    Please try like this html:

    " ?>
    

    ajax/ jquery:

    $(document).ready(function(){
    //handle test button click
    $("button#importSikep").click(function(){
        var checkValues = $('input[name=chkimportsikep]:checked').map(function()
        {
            return $(this).val();
        }).get();
    
        alert(checkValues);
        $('#loading-indicator-runsikep').show();
        $.ajax({
            type:"POST",
            url:"runsikepimport.php", // your php page action
            data:{ chkimportsikep: checkValues }, // 
            cache:false,
            success: function(result){
                $('#loading-indicator-runsikep').hide();
                alert(result);
                $('.modal.in').modal('hide');
                $("#description-status-sikep").load(location.href + " #description-status-sikep");  
                //location.reload(true);
            }
        });
        return false;
    });
    

    });

    PHP action :

        // don't need array variable, but your using $_POST
    if(!empty($_POST['chkimportsikep'])) {
                foreach($_POST['chkimportsikep'] as $table_name) {
                 // do something 
                }
    }
    

提交回复
热议问题