I am not very familiar with jqTouch. But what happens is that the click handler binds to links every time a link is clicked. Thus, each click will skip the verse N + 1 times.
EDIT: I see it now. Your updateVerse function has the following:
$("a.next").tap( function(){ addDayNum();// doesn't work at all //dayNum++;// doesn't work at all //dayNum = dayNum + 1;//doesn't work at all updateVerse(); //alert(dayNum); //alert("next clicked"); }); $("a.prev").tap( function(){ subDayNum();// doesn't work at all //dayNum--;//doesn't work at all //dayNum = dayNum - 1;// doesn't work at all updateVerse(); //alert(dayNum); //alert("previous clicked"); });
This code should run only once and what happens with the addition of the tap() handler each time the link is clicked. That's why it skips N + 1 verses every time you click a link.
Here is what your code looks like:
var dayNum = 30; //---------------------------------------------------------------------- function setupClickHandlers() { $("div#header a.next").tap( function(){ addDayNum(); //dayNum++;// doesn't work at all //dayNum = dayNum + 1;//doesn't work at all updateVerse(); //alert(dayNum); //alert("next clicked"); }); $("div#header a.prev").live('click', function(){ subDayNum(); //dayNum--;//doesn't work at all //dayNum = dayNum - 1;// doesn't work at all updateVerse(); //alert(dayNum); //alert("previous clicked"); }); } function updateVerse(){ //alert("updateVerse called"); $.ajax({ type: "GET", dataType: 'JSON', data: 'day='+ dayNum, url: 'forward.php', success: function(data){ var obj = $.parseJSON(data); $("h2.quote").html(""); $("h3.reference").html(""); $("h2.quote").append(obj.quote); $("h3.reference").append(obj.reference, " ", obj.version); //$("span.version").append(obj.version); //----------------------------------- // JSON string {"id":"1","quote":"For to me, to live is Christ, and to die is gain","reference":"Philippians 1:21","version":"NKJV"} }, error: function(request, error){ alert("problem retrieving json data string"); } }); function addDayNum(){ dayNum = dayNum + 1; //dayNum = dayNum++; } function subDayNum(){ dayNum = dayNum - 1; //dayNum = dayNum--; } } $(document).ready(function(){ $.jQTouch({ icon: 'dailyqoteicon.png', statusBar: false, initializeTouch: 'a.touch' }); setupClickHandlers(); $('a.touch').swipe( function(event, info){ //alert("jQTouch swipe event"); //alert(info.direction); }); });
source share