简体   繁体   中英

How to send different row id via jquery ajax to update table records in another php page by clicking checkboxes?

When I click on both green checkboxes, just the latest table id send, the blow code are both checkbox and jQuery,

Checkbox:

<div class='md-checkbox has-success'>
    <input type='checkbox' id='submit'  value='$id' class='md-check'>
    <label for='submit'>
        <span></span>
        <span class='check'></span>
        <span class='box'></span>
        Submit
    </label>
</div>

jQuery:

$("#submit").change(function() {
    var submit=$("#submit").val();
    var remark=$("#remark").val();
    var submit_date=$("#submit_date").val();
    var string_data = 'id=' + id + '&remark=' + remark + '&submit_date=' + submit_date + '&submit=' + submit;
    alert(string_data);
    $.ajax({
        type: "POST",
        url: "estimation_qc_update.php",
        data: string_data,
        cache: false,
        success: function(html) {
            $("#estimation").html('');
            $("#estimation").html(html);
        }
    });
}); 

在此处输入图片说明

Firstly if there are lots of checkboxes means to say more than one don't use the id instead of that use class.

<input type='checkbox' id='submit' class='tblCheckBox' value='$id' class='md-check'>
$('.tblCheckBox').on('change',function(){
    if($(this).prop('checked') == true){
       var submit=$(this).val();
       var remark=$("#remark").val(); 
       //further make your ajax call.
       //one thing more whenever you've lots of check boxes or whatever        always use on function that not create extra memory
    }
 })

You can cope with this problem by applying common css classes and custom data attributes

eg

 <td calss="btn-submit" data-target-id="unique-record-id-goes-here">submit</td> 

now you can do the miracles!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM