When the page loads, I want to generate a JavaScript loop. The total number of items is depending the PHP string already on the page.
<script type="text/javascript">
function Generation(){
var loopTotal = <?=$TotalNumberOfRows?>;
var innerToUpdate=$("#loopItemSet");
var page=0;
for (var i=0;i<=<?=$TotalNumberOfRows?>;i+=24)
{
page++;
// document.write(i);
innerToUpdate.innerHTML="<a href='link.php?go="+i+"'> page number "+page+"</a>";
}
}
$(document).ready(function(){
Generation();
});
</script>
It should return three links since 24, goes into 52, three times.
This row override the
innerHTMLof your element in each iteration. You could simply add a+like this:or collect all entries in a string first and then update the HTML content of that element just once:
I replaced you call to
innerHTMLwith jQuery’shtml(). In my opinion, if you use jQuery, use it wherever needed.