0

I am new to web development and I am learning to use HTML, CSS, JavaScript, jQuery and AngularJS to make a simple web application. I have a simple problem but I cannot find a simple answer to it.

I have a simple HTML code, in which I have multiple variables that are keeping track of the number of clicks that are made on different positions on the screen, i.e. one variable keeps track of the number of clicks on an image, one variable keeps track of the number of clicks on the right of the image etc.

How can I simply save the values of those variables to an Excel file? I have found very complicated ways to save arrays to Excel, but I was wondering if there is any simpler way to do that! here is a simplified version of the code, I would like to save the values of the variables "goal" and "miss":

<html>
  <head>
    <title>Exercise</title>
  </head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

  <body>
  <img id="myImage" src="ball.gif">

    <style>
    #myImage { position: absolute;
    top:0;
    bottom: 0;
    left: 0;
    right: 0;
    margin:auto;  }
    </style>                                                                             
    <p id = "myGoals"></p>
    <p id = "myMisses"></p>

    <script>
      var goal=0;
      var miss=0;
      var img = document.getElementById("myImage");
      var width = $(img).width();
      var height = $(img).height();

      $(document).ready(function() {
          document.addEventListener("click", function(e) {
          var offset = $(img).offset();
          if (e.target === img) {
            goal++;
          }
          else {
            miss++
          }
          document.getElementById("myGoals").innerHTML = "Goals: " +goal;  
          document.getElementById("myMisses").innerHTML = "Misses: " +miss;  

      }, false);})

    </script>
  </body>
</html>      
Gigi
  • 57
  • 1
  • 10
  • can use libraries or the methods you found...no, there is no *"simple way"* – charlietfl Apr 10 '17 at 13:05
  • 1
    Have a look at some of the answers to this question: http://stackoverflow.com/q/333537/3713362 It'd be easier for you to look at a solution involving exporting to a CSV file. – ACOMIT001 Apr 10 '17 at 13:12
  • Thank you @ACOMIT001 , it works now. Since my variable is changing at every click, how can I tell the app to download the Excel file for example only when a certain key is pressed? – Gigi Apr 10 '17 at 13:32
  • Can you show me the code you are using? – ACOMIT001 Apr 10 '17 at 14:03
  • I am using the code below to save to CSV, but instead of saving those values, I want 2 separate columns for var goal and var miss `var A = [['n','sqrt(n)']]; for(var j=1; j<10; ++j){ A.push([j, Math.sqrt(j)]); } var csvRows = []; for(var i=0, l=A.length; i – Gigi Apr 10 '17 at 14:13

0 Answers0