2017-07-10 6 views
0

選択ボックスでこの値を選択すると、onclickの値がこの行に表示する最初の行に表示されます。選択したオプションのテキストを取得するための enter image description hereCodeigniter Selectbox onclick値

<?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 ""; 
    } 


    ?> 
+0

あなたが選択したオプションの値を取得したいですか。 @June –

+1

あなたのHTMLコードを共有する –

+0

はい私はループとしてそれを取得したい – June

答えて

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> 
+0

大丈夫私はそれを試してみよう – June

関連する問題