mercredi 6 avril 2016

How to tick any given check box inside a form?

for ($i=0; $i<$total_questions_for_exam; $i++) {


        $question_id= $question_and_answers[$i]['question_id'];
        $numberofanswersperquestion = count_answers_belongToOne_questionNew($question_id);
        //die(var_dump($question_id)); 
        $student_answer_per_question = retrieve_student_result ($_SESSION['user_id'], $_GET['quiz_id'], $question_id);
        $correct_answer = $numberofanswersperquestion[0]['answer_name'];

         echo ' <form method="post" id="review_form" name="review_form" action="view_user_summary.php">   
            <table class="table table-bordered table-condensed table-datatable table-hover review_marks">
                <tbody>

                    <tr>
                        <td style="text-align: left;" width="100%"><strong>Question '. ($i+1) .'</strong></td> 
                    </tr>
                    <tr>
                        <td style="text-align: left;" width="100%">' . $question_and_answers[$i]['question_name'] .'</td>
                    </tr>';

                    if($student_answer_per_question == '') 
                      echo  '<tr>
                                <td style="text-align: left;" width="100%" class="warning"><em>Question Not attempted</em><br><strong>Correct Answer is </strong><br>' . $numberofanswersperquestion[0]['answer_name'] . '</td>
                            </tr>';

                    else if ($student_answer_per_question == $correct_answer)

                     echo  '<tr>
                                <td style="text-align: left;" width="100%" class="success"><strong>Your answer is correct.</strong><br>' . $student_answer_per_question .'</td>
                            </tr>';

                    else 
                        echo    '<tr>
                                    <td style="text-align: left;" width="100%" class="danger">
                                        <table style="width: 100%">
                                            <tbody>
                                                <tr>
                                                    <th style="width: 50%"><strong>Your Answer</strong></th>
                                                    <th style="width: 50%"><strong>Correct Answer</strong></th>
                                                </tr>
                                                <tr>
                                                    <td style="width: 50%">' . $student_answer_per_question . '</td>
                                                    <td style="width: 50%">' . $correct_answer .'</td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>';

                    echo 

                    '<tr>
                        <td style="height: 5px;" width="100%">&nbsp;</td>
                    </tr>

                    <tr>
                    <td style="height: 5px;" width="100%">&nbsp;</td>
                    </tr>

                </tbody>
            </table>

            <div class="[ form-group ] correct_answer">
                <input type="checkbox" name="fancy-checkbox-primary"  id="fancy-checkbox-primary" autocomplete="off" />
                <div class="[ btn-group ]">
                    <label for="fancy-checkbox-primary" class="[ btn btn-primary ]">
                        <span class="[ glyphicon glyphicon-ok ]"></span>
                        <span> </span>
                    </label>
                    <label for="fancy-checkbox-primary" class="[ btn btn-default active ]">
                        Correct Answer
                    </label>
                </div>
            </div>';

}

echo '<button class="btn btn-large btn-block btn-primary submitbutton" type="submit" style="margin-top:100px;" name="submit_review">Submit Review</button></form>';

Hi guys this code above basically just pulls all the question and asnwers in my database. What I am trying to achieve is to have a check box within this for loop where it allows the users to tick the box to say that the answer is correct, or if they don't do anything assume the answer is wrong.

Screenshot of how it looks

It display as how I wanted it to be but one problem, when I click on the 2nd check box, the first one still ticking, I do not have control of the 2nd check box. Any idea how I can go about fixing this ?

Thought it would be a good idea to show a video of what I meant, I have provided a link to it.

Problem




Aucun commentaire:

Enregistrer un commentaire