title: Pass a PHP variable dynamically to an AJAX JavaScript function
body: <p>I have a JavaScript function (which users on this forum graciously helped me construct) that passes variables via POST to a PHP file with a query for inserting the data to a MySQL database. </p>
  
  <p>The function is invoked "onchange" for a series of 2000+ rows that are spit out from a MySQL database. I use the ID of the row to give each form field a unique name/id, like this:</p>
  
  <pre><code>echo "=&lt;select name='$AdvertisersSQLResult[id]geolocation' id='$AdvertisersSQLResult[id]geolocation' onchange = 'insertAdvertiser()'&gt;"; 
  </code></pre>
  
  <p>The JavaScript function looks like this:</p>
  
  <pre><code>function insertAdvertiser() {
  var data = $('#&lt;?php echo $AdvertisersSQLResult[id]?&gt;dataid,#&lt;?php echo $AdvertisersSQLResult[id]?&gt;industry,#&lt;?php echo $AdvertisersSQLResult[id]?&gt;geolocation').serialize();
  $.post('/database/InsertAdvertiserRelationship2.php', data);
  return false;
  }
  </code></pre>
  
  <p>As you can see, I'm attempting to pass PHP variables as part of the form id values. However, this doesn't work, as the function is written to the page once (in the  section) without any variables yet populated. </p>
  
  <p>In other words, I'd like to have this JavaScript function utilize whatever PHP variable is being passed to it dynamically. I've looked at other threads about passing a PHP variable to a JavaScript function, but I can't find any reference to how this can be done dynamically, such that the JavaScript function changes to use a different PHP variable each time (if that makes sense).</p>
  
  <p>Thanks for any help...</p>