title: How to pass data to javascript on a WordPress Admin page?
body: <p>I am building a Wordpress plugin to manipulate a custom table in the Wordpress database from an Options Settings page. So far, I'm able to query the database and build an HTML table with the results.</p>
  
  <pre><code>ob_start();
  // query the database and get the records
  // $games contains the records
  
  $htm .= '&lt;table id="pl_table"&gt;';
      // header
      $htm .= '&lt;tr&gt;';
          foreach ( $cols as $col ) {
              $htm .= '&lt;th&gt;'.$col.'&lt;/th&gt;';
          }
      $htm .= '&lt;/tr&gt;';
      // body
      $htm .= '&lt;tr&gt;';
          foreach ($games as $game){
              foreach ($game as $val) {
                  $htm .= '&lt;td&gt;'.$val.'&lt;/td&gt;';
              }
              $htm .= '&lt;/tr&gt;';
          }
  $htm .= '&lt;/table&gt;';
  echo $htm;
  $output = ob_get_contents();
  ob_end_clean();
  echo $output;
  </code></pre>
  
  <p>So far so good. Now I want to make the first column in the table a button that fires a javascript function.</p>
  
  <pre><code>$htm .= '&lt;tr&gt;';
  foreach ($games as $game){
      foreach ($game as $val) {
          if ($game-&gt;ID == $val){
              $htm .= '&lt;td&gt;&lt;button type="button"  id="btn'.$val.'" onclick="myFunction()"&gt;'.$val.'&lt;/td&gt;';
          }
          else {
              $htm .= '&lt;td&gt;'.$val.'&lt;/td&gt;';
          }
      }
      $htm .= '&lt;/tr&gt;';
  }
  </code></pre>
  
  <p>Here is the function in my admin.js file:</p>
  
  <pre><code>function myFunction() {
      document.getElementById("tboxOut").value = jsgame.ID;
  }
  </code></pre>
  
  <p>In my main plugins page, I have enqueue'd the script file.</p>
  
  <pre><code>wp_enqueue_script('pl_script',plugins_url( 'js/admin.js', __FILE__ ));
  </code></pre>
  
  <p>When I open the page in a browser and click a button in column 1, the function fires and I can debug it in the browser.</p>
  
  <p>Now, I need to pass the data in $game to this function and populate a bunch of input boxes, but have had no luck. Here is what I've tried:</p>
  
  <pre><code>$aryGame = (array)$game;
  $htm .= wp_localize_script( 'pl_script', 'jsgame',$aryGame  );
  $htm .= '&lt;td&gt;&lt;button type="button"  id="btn'.$val.'"onclick="myFunction()"&gt;'.$val.'&lt;/td&gt;';
  </code></pre>
  
  <p>But in the browser debuger, I get an error: Uncaught ReferenceError: jsgame is not defined</p>
  
  <p>Obviously, I'm missing some understanding on how to pass data from PHP to the javascript. Any ideas?</p>