Ghugu Ghugu - 2 months ago 5
PHP Question

how to display dropdown as i checked from checkbox

hello m new in php and please help me i am having no idea how it can be done
here is my code

<?php echo form_open("")?>

<div class="left_sel">
<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>
<br>
<br>
<br>
<br>
<div class="left_sel">
<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>
<br>
<br>
<br>
<br>
<div class="permision_col_3">

<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="users" value="<?=$user['user_id']?>" ></span><p><?= $user['f_name']?> </p></li>
</ul>
<? } ?>
</div>
<div class="permision_col_6">
<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[]" class="check_section" value="<?=$section['section_id']?>"></span><p><?=$section['section_name']?></p>

</label>
</li>

<? } ?>

</ul>

</div>


As from checkbox i checked name from name= "users" from Allow permissions now i want to display a drop down with the checked name inside dropdown along with each section (having 4 section) and if i checked two names then also display two names inside the dropdown along with all sections

please provide me solution how to do it in my code i tried various examples but no success

Answer

Add class to checkbox, when you click on it added

  $(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);  

In user html add a div

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