I made an online quiz that takes questions stored in a php database and displays them via jQuery's post method. The user can go to the next question or back to the previous one. I would like to store the user's answers so that at the end I can calculate the right and wrong answers and display the questions the user got wrong. I would like to store the user's answers in jQuery somehow and not in a php database. What would be the best way to go about this? Thanks in advance.
HTML and jQuery
<script>
$(document).ready(function() {
var number = 0; //this is the current # of the question the user is working on
$('#next').click(function() {
number = number +1;
if (number > 1){
$('#prev').css('display','block');
}
$.post('getquestions.php', {number: number}, function(result){
$('#questionArea').html(result);
});
});
$('#prev').click(function() {
number = number -1;
if (number < 2){
$('#prev').css('display','none');
}
$.post('getquestions.php', {number: number}, function(result){
$('#questionArea').html(result);
});
});
});
</script>
<div id='questionArea'></div>
<input type='button' id='prev' value='previous' style='display: none;'/>
<input type='button' id='next' value='next' />
getquestions.php file:
<?php
require '../connect.php';
$question_number = $_POST['number'];
$sql="SELECT * FROM questions WHERE test='1' AND question_number='$question_number' LIMIT 1";
$result=mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$question = $row['question'];
$chA = $row['choiceA'];
$chB = $row['choiceB'];
$chC = $row['choiceC'];
$chD = $row['choiceD'];
$chE = $row['choiceE'];
$qid = $row['qid'];
$correct = $row['correct'];
}
echo "<div id='question'>" . $question . "</div>";
echo "<input type='radio' name='a' value=" . $chA ."> " . $chA . "<br>";
echo "<input type='radio' name='b' value=" . $chB ."> " . $chB . "<br>";
echo "<input type='radio' name='c' value=" . $chC ."> " . $chC . "<br>";
echo "<input type='radio' name='d' value=" . $chD ."> " . $chD . "<br>";
echo "<input type='radio' name='e' value=" . $chE ."> " . $chE . "<br>";
?>