title: Update sql in javascript function
body: <p>I have an ordinary html table in which each cell contains a name. I've added a function to each of these cells, which turns the cells background color green, if it's white and the other way around. However, I would also like to update an mySql datebase, when a cell is clicked, but I can't seem to figure out a good way to do this, without reloading the page (which I would prefer not to do) or using javascript to connect to the server (which seems like a very bad practice). The page has already been loaded at this point. Does anybody have any good suggestions?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var tbl = document.getElementById("table");
          if (tbl != null) {
              for (var i = 1; i &lt; tbl.rows.length; i++) {
                  for (var j = 0; j &lt; tbl.rows[i].cells.length; j++)
                      tbl.rows[i].cells[j].onclick = function () { getval(this); };
              }
          }
  
          function getval(cel) {
              if(cel.style.backgroundColor == "green")
              {
                   cel.style.backgroundColor = "white";
  
                   // Here I would like to update my datebase with mySql
                   // query(UPDATE team SET attended=0 WHERE name = cel.innterText)
                   // (name associated with the cell)
  
              }
              else
              {
                  cel.style.backgroundColor = "green";
                   // Here I would like to update my datebase with mySql
                   // query(UPDATE team SET attended=1 WHERE name = cel.innterText)
                   // (name associated with the cell)
              }
          }   
  &lt;/script&gt;
  </code></pre>