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