title: Make a global variable from onchange event
body: <p>How do I make a global variable from an onchange event so that every functions in my js page can use the value from the variable? Can anyone provide a working sample code. </p>
  
  <p><code>onchange="showTable()"</code> event from <strong>main.php</strong>:</p>
  
  <pre><code>&lt;?php
      $linkID = @ mysql_connect("localhost", "root", "Newpass123#") or die("Could not connect to MySQL server");
      @ mysql_select_db("seatmapping") or die("Could not select database");
      $dbname = "seatmapping";
      $sql = "SHOW TABLES FROM $dbname where tables_in_seatmapping!='userauth'";
      $result = mysql_query($sql);
      $tableNames= array();
  
      while ($row = mysql_fetch_row($result)) {
          $tableNames[] = $row[0];
      }
  
      echo '&lt;select name="tables" id="tables" onchange="showTable(this.value)"&gt;'; 
      echo '&lt;option class="placeholder" selected disabled&gt;Layouts&lt;/option&gt;';
      foreach ($tableNames as $name){
          echo '&lt;option value="'. $name.'"&gt;'.$name.'&lt;/option&gt;';
      }
      echo '&lt;/select&gt;';
  ?&gt;
  </code></pre>
  
  <p><code>onclick="showAvailable()"</code> event from <strong>main.php</strong> as well:</p>
  
  <pre><code>&lt;div class="sliderContainer"&gt;
  
      &lt;div id="slider"&gt;
          &lt;a class="ui-slider-handle" href="#"&gt;Start&lt;/a&gt;
          &lt;a class="ui-slider-handle" href="#"&gt;End&lt;/a&gt;
      &lt;/div&gt;
  
      &lt;p&gt;
      &lt;a id="timer"&gt;&lt;span class="slider-time"&gt;10:00 AM&lt;/span&gt; to &lt;span class="slider-time2"&gt;12:00 PM&lt;/span&gt;&lt;/a&gt;
  
      &lt;a href="#" id="checkAvailable" onclick="showAvailable()"&gt;Avail&lt;/a&gt;
      &lt;a href="#" id="resetAvailable" onclick="resetAvailable()"&gt;Reset&lt;/a&gt;&lt;/p&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>My functions in a .js page:</p>
  
  <pre><code>var tableName;
  
  function showTable(tableName){
    if (window.XMLHttpRequest){
      xmlhttp=new XMLHttpRequest();
    }
    else{
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200){
        document.getElementById("showLayout").innerHTML=xmlhttp.responseText;
        tableName = xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","seatmap.php?tableName="+tableName,true);
    xmlhttp.send();
  }
  
  function showAvailable(){
    var startShift = $('#slider').slider("values", 0);
    var endShift = $('#slider').slider("values", 1);
  
    if (window.XMLHttpRequest){
      xmlhttp=new XMLHttpRequest();
    }
    else{
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200){
        document.getElementById("showLayout").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","seatmap.php?startShift="+startShift+"&amp;endShift="+endShift+"&amp;tableName="+tableName,true);
    xmlhttp.send();
  }
  </code></pre>
  
  <p>And here is a snippet of <strong>seatmap.php</strong>, it's too long but I use the $tableName for both showAvailable and showTable. I also use it for in the query:</p>
  
  <pre><code>&lt;?php
  
  $startSlider=intval($_GET['startShift']);
  $endSlider=intval($_GET['endShift']);
  $tableName = strval($_GET['tableName']);
  
  $linkID = @ mysql_connect("localhost", "root", "Newpass123#") or die("Could not connect to MySQL server");
  @ mysql_select_db("seatmapping") or die("Could not select database");
  
  /* Create and execute query. */
  $query = "SELECT rowId,columnId,status,name,seatid,startShift,endShift from $tableName group by seatid order by rowId, columnId desc";
  $result = mysql_query($query);
  $prevRowId = null;
  $seatColor = null;
  $tableRow = false;
  
  //echo $result;
  echo $tableName;
  </code></pre>
  
  <p>What I want is how to make the value from onchange=showTable(this.value) a global variable so I can use it in the function showAvailable and pass it to a php page. Any kind of help is appreciated. Thank you in advance.</p>