0

I have two local storage variable that keeps count of the user score during a quiz and the number of questions. They are called userMark and questionCounter respectively.

Upon completing a quiz, I parse the localstorage variables as a float and then determine percentage score (userMark/questionCount * 100).

When the user finishes the quiz, the score is displayed. However, I would also like to send this data to a MySQL DB, via a PHP file called marks.php but I would like to do this in the background without the need for clicking a button. After being sent, I would like to clear the localstorage variables.

Is there a way of sending this data without having a form?

Here's what i've got so far:

    <script>    
            // Get LocalStorage Variables and parse as float.

            userMark_float = parseFloat(localStorage.getItem("userMark"));
            questionCounter_int = parseFlat(localStorage.getItem("questionCounter")); 

            // Calculate Percentage Score

            percentage = (userMark_float/questionCounter_float) * 100;
            percentageMark = percentage.toFixed(1);

            // Display Percentage score & userScore/totalScore.

           document.getElementById("percetangeMark").innerHTML = percentageMark;
           document.getElementById("userMark").innerHTML = userMark_int;
           document.getElementById("questionNumber").innerHTML =questionCounter_int;


           // Code for Sending Percentage Mark to MySQL



           // Clear Local Storage
           localStorage.removeItem("userMark");
           localStorage.removeItem("questionCounter");
   </script>
Adnan
  • 2,451
  • 4
  • 24
  • 32

0 Answers0