lundi 23 août 2021

Checkbox: Implode checkbox that have double values

So this is my checkbox

Select all:

<input type="checkbox" id="select_all"/><font size='4'> Select All</font></li>
<? $data=getCheckboxUpdate($id,$month_claim) ?>
    <form name="frmactive" method="post" action="">
    <table border="0">
    <tr><td colspan="5">
         <input class="btn btn-success" name="activate" type="submit" id="activate" value="VERIFY" />
         <input class="btn btn-danger" name="deactivate" type="submit" id="deactivate" value="REJECT" />
    </td>
    </table>

Single checkbox:

    <input name="checkbox[]" type="checkbox" class="checkbox" id="checkbox[]" value="<?php echo $ot['id']; ?>" data-valuetwo="<?php echo $ot['month_claim']; ?>" >

Here my script:

$(document).ready(function(){
    $('#select_all').on('click',function(){
        if(this.checked){
            $('.checkbox').each(function(){
                this.checked = true;
            });
        }else{
             $('.checkbox').each(function(){
                this.checked = false;
            });
        }
    });
    $('.checkbox').on('click',function(){
        if($('.checkbox:checked').length == $('.checkbox').length){
            $('#select_all').prop('checked',true);
        }else{
            $('#select_all').prop('checked',false);
        }
    });
});

And here my function:

function getCheckboxUpdate($id,$month_claim){
    $conn=db();
    if(isset($_POST['checkbox'])){
        $checkbox = $_POST['checkbox'];
        if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
            $id = "('" . implode( "','", $checkbox ) . "');" ;

            **$month_claim = //How do I get this value from checkbox data-valuetwo**

        $sql="UPDATE aims_ot_approval ap LEFT JOIN aims_ot a ON a.id = ap.ot_id 
              SET ap.verify_status = '".(isset($activate)?'VERIFIED':'REJECTED')."',ap.verify_date=CURRENT_TIMESTAMP 
              WHERE a.month_claim = '$month_claim'
              AND a.staff_record_id IN $id" ;
        $result=$conn->query($sql);
        return $result;
    }
    }

Right now, I only succesfully implode one checkbox value to my function. How do I get the value from checkbox data-valuetwo to my function? Thanks as always




Aucun commentaire:

Enregistrer un commentaire