Saving js var data in a mysql table without clicking or inputting by the user

How do I save js var data in a mysql table without clicking or inputting by the user based this script? The only way know how to get JS var data into a mysql database is by create an XMLHttpRequest object, but that doesn’t seem appropriate in this situation. Is there another way? If so, what do you suggest?

<html>
 <head>
 <title>onscroll test</title>

 <script type="text/javascript">
 window.onscroll = scroll;

 function scroll(){
 var down_scroll = window.pageYOffset;
 //alert ("Down_value: " + down_scroll);
 }

</script>
</head>
<body>

<p>item1</p> <p>item2</p> <p>item3</p> <p>item4</p> <p>item5</p>
<p>item6</p> <p>item7</p> <p>item8</p> <p>item9</p> <p>item10</p>
<p>item11</p> <p>item12</p> <p>item13</p> <p>item14</p> <p>item15</p>
<p>item16</p> <p>item17</p> <p>item18</p> <p>item19</p> <p>item20</p>
<p>item21</p> <p>item22</p> <p>item23</p> <p>item24</p> <p>item25</p>
<p>item26</p> <p>item27</p> <p>item28</p> <p>item29</p> <p>item30<p>

</body>
</html>  

Not that I know of. What is the context of the behaviour?