4

i want to put 10 questions from database and a timer on a html form. questions to be displayed one by one when i click next button next question will be shown and when clicked back button previous question should be shown

<form name="form1" bgcolor="red" action="resultbyme.jsp" method="POST">
    <div style="background-color:orange;"> 
        <% qno=n+1;
        ques=rs.getString(4);
        op1=rs.getString(5);
        op2=rs.getString(6);
        op3=rs.getString(7);
        op4=rs.getString(8);
        %>
        <br>Q.<%=qno%>--><%=ques%></br>
        <input type="radio" name="opt<%=qno%>" value="<%=op1%>" /><%=op1%><br>
        <input type="radio" name="opt" value="<%=op1%>" /><%=op2%><br>
        <input type="radio" name="opt" value="<%=op1%>" /><%=op3%><br>
        <input type="radio" name="opt" value="<%=op1%>" /><%=op4%><br>
        <%
            }
        } //end for
    }
    catch(SQLException e)
    {
        out.println("erorr in sql ") ;                        
    }
        %>
        <div bgcolor="blue"><input type="submit" value="submit" name="submit test" /></div>
    </div>
</form>
1
  • i also want to check the result how many out of total questions are correct ( i have less knowledge of html and java script) i tried sumthing i found here like <form name="form1"action="resultbyme2.jsp" method="post"><div align="left"><a href="<%=request.getRequestURL()%>?start=<%=start-1%>">Previous</a><BR></div><div align="right"><a href="%=request.getRequestURL()%>?start=<%=start+1%>">Next</a><br/></div><div id="form" align="centre"> <% if(start==1){%>name=<input type="text" name="name" value="enter name" /><BR><% }%><%start==2)but when i more forward all previous field value get null . Nov 4, 2012 at 16:33

2 Answers 2

1

You can load everything in different div, and show them one after another with JavaScript.

1

You will have a common header and which will handle you timer. your html body will dynamically change (Use ajax for this ) based on user click next or back.

Better to maintain questions numbers hidden in next and back button. So in AJAX call you can get question number and pass to server to get that specific question and. You can display it in defined span or div tag.

  <div id="questionId"> My question is here  </div>

inside javascript

  function loadQuestion(questionNo){

    $.ajax({
     type: "POST",
      url: 'projectName/showQuestion.action',
      data: "quesionNo="+questionNo
      success: function(data) {

        document.getElementById('questionId').innerHTML =data;

      }
    });

 }

This is just a guide and you change thing to suit your approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.