当单击复选框时,它显示多个值?

时间:2019-02-23 06:27:49

标签: php jquery codeigniter

视图:

<script>
    $(document).ready(function(){
        $(".uid").click(function(){
            jid = $(".jid").attr("id");
            uid = $(':checked').map(function() { 
                        return this.id; 
                  }).get().join(',');
            $.ajax({
                type:"POST",
                data:{"jid":jid, "uid":uid},
                url:"<?php echo base_url(); ?>shortlist",
                success:function(data){
                    $(".stage_shortlist").html(data);
                }
            });
        });
        $(document).on("click",".uid_short",function(){
            jid_short = $(".jid_short").attr("id");
            uid_short = $(':checked').map(function() { 
                            return this.id; 
                        }).get().join(',');
            alert(jid_short);
            alert(uid_short);
        });
    });
</script>
<h2>Received</h2>
<section>
    <table class="table table-hover js-basic-example dataTable table-custom m-b-0">
        <thead>
            <tr>
                <th>Name</th>  
                <th>Shortlist</th>
            </tr>
        </thead>
        <tbody>
            <?php
                $this->db->select('*');
                $this->db->from('upload_detail');
                $where = "jid='".$row['job_id']."' and share_with_emp='1'";
                $this->db->where($where);
                $sql = $this->db->get();
                if($sql->num_rows() > 0)
                {
                    $result = $sql->result_array();
                    foreach($result as $recieve)
                    {
            ?>
                        <tr>
                            <td><?php echo $recieve['fname']; ?></td>
                            <td>
                                <div class="fancy-checkbox">
                                    <label>
                                        <input type="hidden" name="jid" class="jid" id="<?php echo $recieve['jid']; ?>"/>
                                        <?php 
                                            if($recieve['shortlist']=='1')
                                            { 
                                                echo '<input type="checkbox" name="uid" id="" class="uid" checked disabled><span>Shortlist</span>'; 
                                            }
                                            else
                                            {
                                                echo '<input type="checkbox" name="uid" id="'.$recieve["uid"].'" class="uid"><span>Shortlist</span>';
                                            }
                                        ?>
                                    </label>
                                </div>
                            </td>
                        </tr>
            <?php
                    }
                }
                else
                {
                    echo "<p>No resume Found</p>";
                }
            ?>
        </tbody>
    </table>
</section>
<h2>Shortlisted</h2>
<section>
    <table class="table table-hover js-basic-example dataTable table-custom m-b-0">
        <thead>
            <tr>
                <th>Name</th>
                <th>Shortlist</th>
            </tr>
        </thead>
        <tbody class="stage_shortlist">
            <?php
                $this->db->select('*');
                $this->db->from('upload_detail');
                $where = "jid='".$row['job_id']."' and shortlist='1'";
                $this->db->where($where);
                $sql_short = $this->db->get();
                $result_short = $sql_short->result_array();
                foreach($result_short as $short)
                {
            ?>
                    <tr>
                        <td><?php echo $short['fname']; ?></td>
                        <td>
                            <div class="fancy-checkbox">
                                <label>
                                    <input type="hidden" name="jid_short" class="jid_short" id="<?php echo $short['jid']; ?>"/>
                                    <?php 
                                        if($short['interview']=='1')
                                        { 
                                            echo '<input type="checkbox" name="uid_short" id="" class="uid_short" checked disabled><span>Shortlist</span>'; 
                                        }
                                        else
                                        {
                                            echo '<input type="checkbox" name="uid_short" id="'.$short["uid"].'" class="uid_short"><span>Shortlist</span>';
                                        }
                                    ?>
                                </label>
                            </div>
                        </td>
                    </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</section>

控制器:

<?php
public function shortlist()
{
    $jid = $this->input->post('jid');
    $uid = explode(",",$this->input->post('uid'));
    $data = array('shortlist'=>'1');
    foreach($uid as $user_id)
    {
        $where = "uid='".$user_id."' and jid='".$jid."'";
        $this->db->where($where);
        $sql = $this->db->update('upload_detail',$data);
    }
    if($sql==true)
    {
        $this->db->select('*');
        $this->db->from('upload_detail');
        $where = "jid='".$jid."' and shortlist='1'";
        $this->db->where($where);
        $sql_short = $this->db->get();
        $result_short = $sql_short->result_array();
        foreach($result_short as $short)
        {
?>
            <tr>
                <td><?php echo $short['fname']; ?></td>
                <td>
                    <div class="fancy-checkbox">
                        <label>
                            <input type="hidden" name="jid_short" class="jid_short" id="<?php echo $short['jid']; ?>"/>
                            <?php 
                                if($short['interview']=='1')
                                { 
                                    echo '<input type="checkbox" name="uid_short" id="" class="uid_short" checked disabled><span>Shortlist</span>'; 
                                }
                                else
                                {
                                    echo '<input type="checkbox" name="uid_short" id="'.$short["uid"].'" class="uid_short"><span>Shortlist</span>';
                                }
                            ?>
                        </label>
                    </div>
                </td>
            </tr>
<?php
        }
    }
    else
    {
        echo '<p>Unable to proceed!</p>';
    }
}
?>

在这段代码中,我更新了1标题部分的uid onclick recieved上的候选列表值,并从shortlist控制器进行了响应调用,该方法工作正常但存在问题是当我单击类uid_short时,它会警告alert(uid_short);内部的多个值,我不知道我在哪里做错了吗?请帮我解决这个问题。

谢谢

0 个答案:

没有答案