Please help me:
My code is going into an infinite loop after clicking on a link.
Here is my Code:
<html>
<head>
<title>Assignment</title>
<script language="javascript">
var records_per_page = 5;
var total_records = 35;
function pagination(current_page){
var initial_page = 1;
var total_page = 0;
var page = '';
if(total_records % records_per_page == 0)
{
total_page = total_records / records_per_page;
}
else if(total_records % records_per_page != 0)
{
total_page = ((total_records - (total_records % records_per_page))/records_per_page) + 1;
}
if(total_page == initial_page)
{
page = 'Page: ' + initial_page ;
}
else if(total_page > initial_page && current_page == initial_page)
{
page = 'Pages: ' + initial_page ;
}
else if(total_page > initial_page && current_page > initial_page)
{
page = 'Pages: <a href="javascript:void(0);" onclick="pagination(1)" >1</a>';
}
for(var p = initial_page + 1; p < current_page; p++)
{
page += ' <a href="javascript:void(0);" onclick="pagination(' + p + ')" >' + p + '</a>';
}
if(current_page > initial_page)
{
page += ' ' + current_page ;
}
for(var q = current_page + 1; q <= total_page; q++)
{
page += ' <a href="javascript:void(0);" onclick="pagination(' + q + ')" >' + q + '</a>';
}
document.writeln("<div id='pageNavPosition'></div>")
var element = document.getElementById('pageNavPosition');
element.innerHTML = page;
}
</script>
</head>
<body>
</body>
</html>
<script type="text/javascript">
pagination(1);
</script>