I am making an online exam but the timer part has a problem. Every time a user click on the next button to get a new page, the timer restarts. Here is my code. I am using laravel
http://paste.laravel.com/iOo
I also want to add the option of saving and exiting if one cannot complete the exam. Any help will be greatly appreciated.
You may want to try this way:
- When test starts, create an session variable for the current test for holding questions, for example, 'testQuestions'
- Create a function that will send json output containing a single question from 'testQuestions' array. So whenever you query that url with proper index, you get that question. you can also add additional information, such as nextQuestionIndex, prevQuestionIndex, etc., when sending that question. They will help you to crate Next and Previous buttons on frontend.
- Then on front-end, you can create multiple sections (or divs with IDs), one for displaying timer, one for displaying question.
- Then write function in JavaScript for click events on next and previous button. You can send ajax request and get json response containing next question. You can modify the content of current question to display next or previous question.
You can improve upon this strategy and submit the questions form when Next or Previous button is clicked. This way, you will be updating answer for a question and receiving next/previous question in the single call. Because you will be using ajax request, you can avoid page refresh.
You can record the start time for the exam in a cookie and then each page can read that cookie when the page loads to see what the exam start time was.