<script>
$(document).ready(function(){
$("#submit").click(function(e){
e.preventDefault();
uid = $("input[name='user_id']:checked").map(function() {
return this.id;
}).get().join(",");
$.ajax({
type:"POST",
data:{"uid":uid},
url:"<?php echo base_url(); ?>hr/shortlist",
success:function(data){
setTimeout(function(){
location.reload();
}, 1000);
}
});
});
});
</script>
<table>
<thead>
<tr class="info">
<th>Check</th>
<th>Recruiter Id</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" name="user_id" id="uid1211120937" class="user_id">
</td>
<td>20181123091338</td>
</tr>
<tr>
<td>
<input type="checkbox" name="user_id" id="uid1211092847" class="user_id">
</td>
<td>20181123091338</td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" id="submit" value="short"/>
入围名单.php
$uid = explode(",",$this->input->post('uid'));
foreach($uid as $user_id)
{
$data = array('shortlist'=>'1');
$this->db->where('uid',$user_id);
$query = $this->db->update('personal_detail',$data);
}
在这个问题中,我有多个复选框。现在,如果我选中了所有复选框,那么shortlist must be 1 for all
将被更新,如果我取消选中某些复选框,则uncheck checkbox value will be 0
将被更新。那么,我该怎么做呢?请帮帮我。
谢谢
您需要查找与userid相关的所有复选框状态。
$(document).ready(function(){
$("#submit").click(function(e){
e.preventDefault();
var uids = [];
$("input[name='user_id']").map(function() {
uids.push({id: this.id, value: this.checked ? 1 : 0});
});
$.ajax({
type:"POST",
data:{"uid":uids},
url:"<?php echo base_url(); ?>hr/shortlist",
success:function(data){
setTimeout(function(){
location.reload();
}, 1000);
}
});
});
});
现在已进入候选名单.php
$uid = $this->input->post('uid');
foreach($uid as $user)
{
$data = array('shortlist'=> $user['value']);
$this->db->where('uid',$user['id']);
$query = $this->db->update('personal_detail',$data);
}