jeudi 26 novembre 2015

Get all checkbox value generated by JSP for loop

I'm new at JSP and web development, I have a form which used to do a multiple choice test and I want to do that when user click on submit button my page will calculate number of correct answer but my problem is I don't know how to collect user's anwser to count number of correct answer. Can you show me how to solve it? Sorry for my bad English and thanks for your help! Here is my form:

        <form class = "exam" action="#" method= "get" language = JAVASCRIPT name="A1Exam">
    <%
                        A1DrivingTest a1DrivingTest = new A1DrivingTest(
                        DatabaseConnection.connect());
                        Question[] question = a1DrivingTest.getLawQuestions();
                        for (int i = 0; i < question.length; ++i) {
                    %>
                    <table border="2">
                        <tr>
                            <th>NỘI DUNG CÂU <%=i + 1%></th>
                        </tr>
                        <tr>
                            <td><img alt="image" src=<%=question[i].getImageUrl()%/></td>
                        </tr>
                        <tr>
                          <td id name>
                            <ul class= "listRadioBtn">
                            <li>
                                <input type="checkbox" name="checkbox" value = "1"/>
                                <p id="number">1</p> 
                            </li>
                            <li>
                                <input type="checkbox" name="checkbox" value = "2"/>
                                <p id="number">2</p>
                            </li>
                            <li>
                                <input type="checkbox" name="checkbox" value = "3"/>
                                <p id="number">3</p>
                            </li>
                            <li>
                                <input type="checkbox" name="checkbox" value = "4"/>
                                <p id="number">4</p>
                            </li>
                            </ul>

                            <p id= "correctAnswer">correct answer: <%=%></p>

                            </td>
                        </tr>

                    </table>
                    <%
                        }
                    %>
        <p id = "numbOfCorrectAnswer"></p>
        <input type="submit" id="submitBtn" language= JAVASCRIPT name="submit" title="Submit" />
    </form>




Aucun commentaire:

Enregistrer un commentaire