title: php vars are updating but javascript function shows allways first value
body: <p>I have a php class that set values and updates them. I use getters methods to access those varibles from a javascript function and show them in screen. My problem is when I launch that javascript code, my vars are shown allways with the first values they get. I've checked them and they are up to date when I call <code>myCreateFunction();</code> but is like this function launches before the php vars are updated. I'm new in javascript and some help would be appreciated, thanks!</p>
  
  <pre><code>&lt;?php    
      class TableRows {
  
          public $offerId = 0;
  
          public function setOfferId(){
              $this-&gt;offerId ++;
          }
          public function getOfferId(){
              $this-&gt;offerId;
          }
  
      }
  
      $tb = new TableRows(); 
  ?&gt;
  &lt;script&gt;
      function myCreateFunction(string) {
          var offerId =  '&lt;tr&gt;&lt;th&gt;'+&lt;?php echo json_encode($tb-&gt;getOfferId()); ?&gt;+'&lt;/th&gt;&lt;/tr&gt;';
          var table = document.getElementById("myTable");
          var row = table.insertRow(-1);
          var cell1 = row.insertCell(0);
          cell1.innerHTML = offerId;
      }
  &lt;/script&gt;
  &lt;script&gt;
      myCreateFunction();
  &lt;/script&gt;
  &lt;?php
      $tb-&gt;setOfferId();
  ?&gt;
  &lt;script&gt;
      myCreateFunction()
  &lt;/script&gt;
  </code></pre>