如何从复选框中选中显示下拉列表

时间:2016-09-19 11:46:02

标签: php

你好我是PHP的新手,请帮助我,我不知道如何做到这一点 这是我的代码

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
<?php echo form_open("")?>

<div class="left_sel" id="month">
            <label align="left">Enter Month</label>
            <select id="month" name="month" class="input-text" value="<?=set_value('month',$this->input->post('month'))?>">
                <option value="<?=set_value('month',$this->input->post('month'))?>">&nbsp;&nbsp;Select Month</option>
                <option value="January" <?=($this->input->post('month') == 'January')?'selected':''?>>&nbsp;&nbsp;January</option>
                <option value="February" <?=($this->input->post('month') == 'February')?'selected':''?>>&nbsp;&nbsp;February</option>
                <option value="March" <?=($this->input->post('month') == 'March')?'selected':''?>>&nbsp;&nbsp;March</option>
                <option value="April" <?=($this->input->post('month') == 'April')?'selected':''?>>&nbsp;&nbsp;April</option>
                <option value="May" <?=($this->input->post('month') == 'May')?'selected':''?>>&nbsp;&nbsp;
                May</option>
                <option value="June" <?=($this->input->post('month') == 'June')?'selected':''?>>&nbsp;&nbsp;
                June</option>
                <option value="July" <?=($this->input->post('month') == 'July')?'selected':''?>>&nbsp;&nbsp;
                July</option>
                <option value="August" <?=($this->input->post('month') == 'August')?'selected':''?>>&nbsp;&nbsp;August</option>
                <option value="September" <?=($this->input->post('month') == 'September')?'selected':''?>>&nbsp;&nbsp;September</option>
                <option value="October" <?=($this->input->post('month') == 'October')?'selected':''?>>&nbsp;&nbsp;October</option>
                <option value="November" <?=($this->input->post('month') == 'November')?'selected':''?>>&nbsp;&nbsp;November</option>
                <option value="December" <?=($this->input->post('month') == 'December')?'selected':''?>>&nbsp;&nbsp;December</option>
            </select>
        </div>

        <div class="left_sel" id="employee" style="display:none">
            <label align="left">Select Employee</label>

            <select id="month" name="assigned_for" class="input-text" >
            <option >&nbsp;&nbsp;Select Employee</option>
            <? foreach($users as $user){?>
                <option value="<?=$user['user_id']?>">&nbsp;&nbsp;<?=$user['f_name']?></option>
            <? } ?>
     </select>
        </div>  

        <div id ="both" >
<div class="permision_col_3" style="display:none;" id="permissions">

 <h1 class="heading_name">Allow permissions</h1>
<?php foreach($user_names as $user){ ?>
<ul class="name">
<li><span class="users_check">
    <input type="checkbox" name="team_leads[]" class="chkbox" value="<?=$user['user_id']?>" ></span><p><?= $user['f_name']?> </p></li>
</ul>
 <? } ?> 
 </div>
<div class="permision_col_6"  style="display:none;" id="section">
 <h1 class="heading_name">Sections</h1>
 &nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="check"/>&nbsp;Select all
 <?php foreach($sections as $section){ ?>

<ul class="name">
<li>
<label>
<span class="users_check"><input type="checkbox" name="section_ids[]"   value="<?=$section['section_id']?>"></span><p><?=$section['section_name']?></p>
<div id="user-drop-down" class="right_sel">
    <select  class="input-text" >
            <option >&nbsp;&nbsp;Select permissions</option>
            <? foreach($user_names as $user){?>
                <option value="<?=$user['user_id']?>">&nbsp;&nbsp;<?=$user['f_name']?></option>
            <? } ?>
     </select>
</div>

            </label>

</li>

 <? } ?>

</ul>

</div> 
</div> 


<div id="submit" style="display:none;">
<button id ="submit" class="btn btn-default">ADD EVALUATION</button>
</div>
    <?php echo form_close();?>

<script>
$("#check").change(function () {
    $(".check_section").prop('checked', $(this).prop("checked"));
});
</script>
<script>
$(document).ready(function(){

    $("#month").change(function(){
         $("#employee").show();
          $("#permissions").hide();
          $("#section").hide();
          $("#submit").hide();
    });
     $("#employee").change(function(){

         $("#permissions").show();
          $("#section").show();
          $("#submit").show();
    });

    });


</script>

在“选择权限”下,我想显示“我已选择或选中的允许权限名称”的名称 请帮忙

1 个答案:

答案 0 :(得分:1)

将类添加到复选框,单击时添加

  $(document).on('click', '.chkbox', function(event) {
        var user_array = [];
        $('input[name="multi-section_ids-test"]:checked').each(function() {
            user_array.push(this.value);            
        });     
    });
  var list = "<select>";
  for(var i = 0; i < user_array.length; i++)
  {    
    list += "<option value="+ user_array[i] +">user_array[i]</option>";                     
  }       
  list += "</select>";  
  $('#user-drop-down').html(list);  

在用户html中添加div

  <div id="user-drop-down"></div>