Hello there guys! I am having a spot of bother with a code I am developing to show 10 Magazines at a time that is being fed from an xml file. I have it working to some extent, FF and IE7+8 do not like it, maybe as it says there is an error on line 62 - being the core function calling the data to be fed in.
Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="robots" content="noindex, nofollow" />
<title>Brave Creative - Online Archive</title>
<link rel="stylesheet" href="css/global.css" media="screen" />
<script type="text/javascript" charset="UTF-8" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "issues.xml",
dataType: "xml",
success: function(xml) {
var shelf = $('#shelf-items');
var startIndex = 0;
var howMany = 10;
var $issues = $(xml).find('issue');
var totalIssues = $issues.length;
var numPages = Math.ceil(totalIssues / howMany)
$('span.issuecount').html(+totalIssues+' Issues - '+numPages+' Pages');
var displayIssues = function() {
var $issuesPaginated = $issues.slice( startIndex , (totalIssues - startIndex) + howMany );
$('#shelf-items li').fadeOut(500);
$issuesPaginated.each(function(){
var id = $(this).attr('id');
var date = $(this).find('date').text();
var cover = $(this).find('cover').text();
var issue = $(this).find('issuenumber').text();
var url = $(this).find('url').text();
$('<li id="'+id+'"></li>').html('<a href="'+url+'"><img src="images/covers/'+cover+'" alt="" /></a><br />'+date+' - #'+issue+'').fadeIn(500).appendTo(shelf);
});
}
$('#prevIssueButton').click(function() {
if( startIndex < howMany) {
startIndex -= howMany;
displayIssues();
}else {
startIndex = 0;
displayIssues();
$('span.error').html('No Issues to Display - You are now on Page 1').fadeIn(300).fadeOut(3000);
}
});
$('#nextIssueButton').click(function() {
if( startIndex + howMany <= totalIssues) {
startIndex += howMany;
displayIssues();
}else {
$('span.error').html('No Issues to Display - You are now on Page 1').fadeIn(300).fadeOut(3000);
startIndex = 0;
displayIssues();
}
});
displayIssues().fadeIn(500);
}
}); // end ajax call
}); // end document-ready
</script>
</head>
<body>
<div id="bc-publish"><span></span></div>
<br />
<div id="wrapper">
<header>
<h1>Online Archive: <span>FSM</span></h1>
</header>
<section id="buttons">
<a href="#" id="prevIssueButton" title="Toggle Previous Entries">Previous</a>
<a href="#" id="nextIssueButton" title="Toggle Next Entries">Next</a>
<span class="error"><a></a></span>
<div class="clear"></div>
</section> <!-- /buttons -->
<section id="shelf">
<ul id="shelf-items"></ul>
<div class="clear"></div>
</section> <!-- /shelf -->
<br />
<span class="issuecount"></span>
<br /><br />
<span class="logo"><a href="http://www.bravecreative.co.uk" title="Brave Creative"><img src="images/brave-creative-logo.jpg" alt="Brave Creative" /></a></span>
<span class="address">
<span>t.</span> 01733 392978 <span>m.</span> 07719442825<br />
<span>e.</span> [email protected]<br />
4 Milnyard Square, Orton Southgate, Peterborough PE2 6CX
</span>
<div class="clear"></div>
</div> <!-- /wrapper -->
</body>
</html>
The previous and next buttons do not work correctly, for instance I click next and I go to page 2, click next again - its blank, and click one last time I get told I have no more results to view. But if i click previous to start of with and go back 3 times (to the start again) then click next I can cycle back up to the same issue, this has really baffled me, any help would be deeply appreciated!