title: How to pass variables to a dynamically created javascript onclick function?
body: <p>I am trying to create an onclick event that updates the values of a bootstrap modal element with results from a MySQL ajax query:</p>
  
  <pre><code>function UpdateModal($id){
    document.getElementById("modal_id").value=$id;
  }
  
  $results = GetMySQLResults();
  
  button.onclick = function(){
  
          UpdateModal($results[0]["id"]);
  
  }
  </code></pre>
  
  <p>However the problem is it always says "$result" is undefined when I click the button.</p>
  
  <p>Is there a way to solve this without me having to dynamically create a modal?</p>