title: javascript loader in php foreach
body: <p>I'm trying to make a little javascript loader. My code:</p>
  
  <pre><code>&lt;?
  //COUNT TOTAL PURCHASE INVOICES
  $i = 0;
  foreach($xml-&gt;tr as $purchase) 
  {
      $i++;
  }
  $steps = 100 / $i;
  
  $steps = str_replace(',', '.', $steps);
  
  
  foreach($xml-&gt;tr as $purchase) 
  {   
      ?&gt;
      &lt;script type="text/javascript" charset="utf-8"&gt;
      $(document).ready(function() 
      {
          var loaderValue = $("#loaderValue").val();
          newLoaderValue = parseFloat(loaderValue) + parseFloat("&lt;?=$steps?&gt;");
  
          $("#loaderValue").val(newLoaderValue);
          $(".connect_loader").width(newLoaderValue+"%");
      });
      &lt;/script&gt;
      &lt;?
  }
  ?&gt;
  </code></pre>
  
  <p>The script worked but the problem is that the javascript runs after php is ready so the loader is in one step at 100%.</p>
  
  <p>Is there another simple way to do this?</p>