2016-11-19 10 views
0
  1. 私のコントローラのコード:foreachループの各ラジオボタンの値を取得します

    $model = customer::all(); 
    return View::make('admin.test.startTest') 
    ->with('title','Question and answer') 
    ->with('data',$model); 
    
  2. この私の見解コード:

    foreach($data as $value) { 
    ?>   
    <p>{{ $value-> Qid }}) 
    {{ $value-> opt }} 
    </p>  
    <?php   
    if(($value ->QuestionType) == "MCQ") 
    {?> 
    <ul> 
        <li><b>A: </b>{{$value->opt1}}</li> 
        <li><b>B: </b>{{$value->opt2}}</li> 
        <li><b>C: </b>{{$value->opt3}}</li> 
        <li><b>D: </b>{{$value->opt4}}</li> 
    </ul> 
    Select one of the following options:<br> 
    <input type="radio" name="answers[{{ $value-> opt }}]" value="A" ">{{   $value->opt1}}<br> 
    <input type="radio" name="answers[{{ $value-> opt }}]" value="B" ">{{ $value->opt2}}<br> 
    <input type="radio" name="answers[{{ $value-> opt }}]" value="C" ">{{ $value->opt3}}<br> 
    <input type="radio" name="answers[{{ $value-> opt }}]" value="D" ">{{ $value->opt4}}<br> 
    <?php } elseif(($value ->QuestionType) == "truefalse") {?> 
    Select one of the following options:<br> 
        <input type="radio" name="answers[{{ $value-> opt }}]" value="true" ">True<br> 
        <input type="radio" name="answers[{{ $value-> opt }}]" value="false" ">False<br> 
    <?php } else {?> 
    <input type="radio" name="answers[{{ $value-> opt }}]" value="ok" ">OK<br> 
    <input type="radio" name="answers[{{ $value-> opt }}]" value="agree" ">Agree<br> 
    

    • 私はlaravelに使用している
    • は、私はすべての値が
    • は、どのように私は、入力フィールドの値を取得することができ、結果との比較に取得したいのデータベースからデータを取得
    • forループの入力フィールドa
    • 入力フィールドの値はどこで入手できますか

    • 問題は、私は 値が表示され、各ループのためのラジオボタンを置くしかし、あなたはラジオの名前を持つボタンといくつかを印刷する必要があり、選択した値

答えて

0

を取得していないですクラスは、この下の例では、私はここで

nameとしてclassとしてselectRAgeをとっていると、サンプルHTありますボタンを選択し、上記のコードのデフォルトでミリリットル

<input type="radio" name="Age" class="selectR" value="23">23 
<input type="radio" name="Age" class="selectR" value="24">24 
<input type="radio" name="Age" class="selectR" value="25">25 
<input type="radio" name="Age" class="selectR" checked value="26">26 
<input type="radio" name="Age" class="selectR" value="27">27 

あなたはラジオボタン値を選択し取得する

$(".selectR").each(function(){ 
     if($(this).prop("checked")){ 
      console.log($(this).val()); //24 will console 
     } 
    }); 
をしたい場合はjqueryの

$(".selectR[value='24']").prop('checked',true); 

で確認として24を設定する26

です

関連する問題