I'm trying to create an online quiz that uses JS script. What I'd like to do is take the varibles "Percentage " and "n" from the JS script function and insert them into MySql. Code below.
Code:
<script type="text/jscript"> function quizResult(form, questionArray) { totalQuestions = form.totalQuestions.value; totalCorrect = 0; checkedValue = new Array(); quiz.style.visibility = "hidden"; var n = prompt("Enter UserID Please", "Type your Name here"); for (counter1 = 0; counter1 < totalQuestions; counter1++) { currentQuestion = eval("form.Q" + String(counter1)); currentAnswer = eval("form.A" + String(counter1)); checkedValue[counter1] = "NA"; for (counter2 = 0; counter2 < 4; counter2++) { if (currentQuestion[counter2].checked) { checkedValue[counter1] = currentQuestion[counter2].value; } } formComplete = true; if (checkedValue[counter1] == currentAnswer.value) { totalCorrect++; } else if (checkedValue[counter1] == "NA") { formComplete = false; break; } } if (formComplete) { for (counter3 = 0; counter3 < totalQuestions; counter3++) { document.write("<p>"); document.write("<b>Question: " + questionArray[counter3][0] + "</b><br><br>"); if (questionArray[counter3][5] == checkedValue[counter3]) { document.write("<b>Your Answer: </b>" + questionArray[counter3][checkedValue[counter3]] + "<b><span style='color: #25E01B'> -- Correct</span></b><br>"); } else { document.write("<b>Your Answer: </b>" + questionArray[counter3][checkedValue[counter3]] + "<b><span style='color: #FF0000'>-- Incorrect</span></b><br>"); document.write("<b>Correct Answer: </b>" + questionArray[counter3][questionArray[counter3][5]] + "<br>"); } document.write("</p>"); } totalIncorrect = totalQuestions - totalCorrect; percentage = Math.floor((totalCorrect / totalQuestions * 100)); document.write("<p><br> <b> === QUIZ RESULTS FOR === <b>" + n + "<br> <br>"); document.write("<b>Total Questions: </b>" + totalQuestions + "<br>"); document.write("<b>Correct Answers:</b> " + totalCorrect + "<br>"); document.write("<b>Incorrect Answers: </b> " + totalIncorrect + "<br>"); document.write("Result: " + percentage + "%</p>"); document.write(percentage); if (percentage >= 75) { document.write(" <h3> Congratulation You Pass the Quiz </h3>"); } else { document.write('<H2><b><span style="color: #FF0000"> Sorry, You did not Pass the Quiz. Try Again. </H2><b></span>'); } } else { alert("You did not complete the quiz!"); quiz.style.visibility = "visible"; } } function Redirect() { top.location.replace('Timeover.html'); } function RedirectWithDelay() { window.setTimeout("Redirect();", 60000); } </script>
Comment