Codeigniter Selectbox onclick value

时间:2017-07-10 06:08:12

标签: select onclick

在选择框中选择此值后,onclick值会显示在我要在此行上显示的第一行。 enter image description here

<?php 
  if($this->uri->segment("4")!=""){
    $count=$this->uri->segment("4");
    $nof = "0";
  while($nof!=$count){
  $nof++;
  echo '  

      <div class="box box-default">
      </br>
        <div class="form-group">
        <label for="label" class="col-sm-2 control-label">Label</label>
        <div class="col-sm-10">
                  <input type="text" class="form-control" name="label[]" id="label" placeholder="Label" value="" required>


        </div>
      </div>
      <div class="form-group">
        <label for="type" class="col-sm-2 control-label">Input Type</label>
        <div class="col-sm-10">

          <select class="form-control" name="type[]" id="type" data-toggle="collapse" onclick="add_forTextfield(this.value)"
            required>
              <option selected="selected" value="" disabled="">~ Select Type ~</option>
              <option value="Datepicker">Date picker</option>
              <option value="Selectbox">Select box</option>
              <option value="Textarea">Text area</option>
              <option value="Textfield">Text field</option>
          </select>
        </div>
      </div>

          <div id="addforTextfield">

      </div>
    ';
   }
   }else{
       echo "";
    }


   ?>

1 个答案:

答案 0 :(得分:0)

获取所选选项文本:

您的选择框应该是:     

<select class="form-control yourSelectBoxClass" name="type[]" id="type" data-toggle="collapse" required>
 // Your options

</select>

<script type="text/javascript">
$('body').on('click', '.yourSelectBoxClass', function(e) {

  //For Getting Text
    var your_selected_text = $(this).find(":selected").text();

  // To add the selected value text into the input 
  $('.your_input_class').val(your_selected_text );



 // For Getting Value
   var your_selected_value = $(this).find(":selected").val();

  // To add the selected value into the input 
   $('.your_input_class').val(your_selected_value);
});
</script>