title: Javascript function return value into PHP variable
body: <p>I have the following code which outputs a select menu...</p>
  
  <pre><code>echo "&lt;select name='household' id='house' onchange='updateHousehold()'&gt;";
      while ($row = $result-&gt;fetchArray()) {
          $housename = $row['name'];
          echo "&lt;option value='$housename'&gt;";
              echo $housename;
          echo "&lt;/option&gt;";
      }
  echo "&lt;/select&gt;";
  </code></pre>
  
  <p>...and the following javascript function:</p>
  
  <pre><code>function updateHousehold() {
      var housename = document.getElementById("house").value;
      return housename;
  }
  </code></pre>
  
  <p>I'm trying to have the select menu such that the value of it is always stored in a PHP variable. So it would be in a php variable upon the loading of the page, but if the user changes the value it should update accordingly.</p>
  
  <p>I know I need to use AJAX to do this, however I don't understand how to use it at all - all the answers on stackexchange I either didn't understand or didn't work (probably because I did it wrong).</p>
  
  <p>How can I store the function's return value in a variable, explained in very simple terms and good code examples?</p>
  
  <p><em>Extra: I'm going to be using this variable to query a sql query, so this query would need to be called every time the value of the select changes. I can do this via a PHP function, however is there any way I can call the PHP function after the value of the select input changes?</em></p>