views:

28

answers:

0

I have a site, this site allows its users to search through a large and expansive list of books and they add from this list to their own custom lists. By default the lists they add to is uncategorized. So after searching around on the site they finally come round to their own custom list and they want to break down and add items in it to specific categories. The categories are predefined and all else its option based kinda like a, b, c, d... Now where I am getting stuck is I have noticed that a function I wrote up runs multiple times every time a user uses the function. When the function is first run it runs smooth as anticipated. However when you do it a second time a third time a forth even. The events seem to queue up for a lack of better description. On the second run through the function which is based off a live click the functions does what it did the first time, then does what it was supposed to do for the second time. If you click the function a 3rd time it follows suit best way I can graph it in concept of how im trying to convey it is.

First Run: 1, done. Second Run: 1, 2, done. Third Run: 1, 2, 3, done. What its supposed to do is run the like the first run per click. I think some how but not sure how or what is causing it. Its creating a log or a queue I dont know im not sure I read something on bubbling and propagation and still cant fix it, is any one able to take a quick glance and tell me how I can fix this? Ive been at it for a couple days trying many different ideas and always end up stuck where I am at now.

$j('.booksort').click(function(e){e.preventDefault();var whatNum = $j(this).attr('rel'); loadmsgPopUp();

var hideUnMe = $j(this).parents(".unsortme").eq(0); $j('#msgTitle').html('Categorize my Book'); $j('#msgBody').html("Processing Please wait.."); $j('#msgBottomLeft').html(' '); $j('#msgBottomRight').html('Cancel'); var myvar = $j(this).attr('rel');
var arr = myvar.split('-'); var isbn = arr[1]; var member = arr[0]; $j.post("ucp_briefcase-cat_title.php", {isbn: arr[1], member: arr[0]}, function(data){ var myvar = data;
var arr = myvar.split('|z|'); var msgType = arr[0]; if(msgType == "fail"){ var errType = arr[1]; if(errType == "noData"){$j('#msgBody').html("Error: No book data provided.");} else if(errType == "invalidData"){$j('#msgBody').html("Error: data provided is invalid.");} else if(errType == "book-notfound"){$j('#msgBody').html("Error: Could not find book.");} else if(errType == "book-notinBC"){$j('#msgBody').html("Error: This book is not part of your briefcase.");} else {$j('#msgBody').html("Error: An unexpected error has occured.");} } else if(msgType == "pass"){ var myvar = arr[1]; var arr = myvar.split('|:|'); var myYears = arr[0]; var myTitle = arr[1]; var yearArr = myYears.split('|||'); var getTitle = arr[1]; $j('#msgBody').html(""+getTitle+"

Choose Semister: "+ "Spring"+ "Summer"+ "Winter"+ "

"+ "Choose Year: "+ ""+yearArr[0]+""+ ""+yearArr[1]+""+ ""+yearArr[2]+""+ ""+yearArr[3]+""+ "

" + "" );

  $j('#add2sort').live('click', (function(e){
    e.preventDefault();

       var xmysemister = $j("#mysemister").val();
    var xmyyear = $j("#myyear").val();
    $j.post("ucp_briefcase-addnew.php", {isbn: isbn, member: member, mysemister: xmysemister, myyear: xmyyear}, function(data){
    $j('#msgBody').html("Validating your information...");
        var myvar = data;
     var arr = myvar.split('|:|');
     var msgType = arr[0];
      if(msgType == "fail"){
       var errType = arr[1];
       if(errType == "noData"){$j('#msgBody').html("Error: No book data provided.");}
       else if(errType == "invalidData"){$j('#msgBody').html("Error: data provided is invalid.");}
       else if(errType == "book-notfound"){$j('#msgBody').html("Error: Could not find book.");}
       else if(errType == "book-notinBC"){$j('#msgBody').html("Error: This book is not part of your briefcase.");}
       else {$j('#msgBody').html("Error: An unexpected error has occured.");}
      }
      else if(msgType == "pass"){
       var myYear = arr[1];
       var mySemister = arr[2];
       var myMembID = arr[3];
       var myISBN = arr[4];
       var myLayoutID = arr[5]; 
       var sortCount = $j('#listnext').val();
        $j.post("ucp_briefcase-layout.php", {layoutID: myLayoutID, layoutOrder: sortCount}, function(data){
        var myLayout = data;
        if(sortCount === 0){sortCount = 1;}else{sortCount++;}
                 $j('#listnext').val(sortCount);
                 $j('#sortme').append("<li id=\"menu_"+sortCount+"\" class=\"aborder\"><div class=\"listleft\">&nbsp;</div><div class=\"listtitle\">"+myTitle+"</div><div class=\"listright\">"+mySemister+" "+myYear+"</div><div class=\"stsettings\"><a href=\"#\" class=\"editN\" rel=\""+myISBN+"\"><img src=\"img/ucp_book_editIcon.png\" width=\"20\" height=\"20\" border=\"0\" alt=\"Edit Semister Info\" /></a><a href=\"#\" class=\"removeN\" rel=\""+myISBN+"\"><img src=\"img/ucp_book_deleteIcon.png\" width=\"20\" height=\"20\" border=\"0\" alt=\"Remove Book\" /></a><a rel=\""+myISBN+"\" class=\"sellmyN\" href=\"#\"><img src=\"img/ucp_book_sellIcon.png\" width=\"20\" height=\"20\" border=\"0\" alt=\"Sell My Copy\" /></a></div><div class=\"listnl\"></div></li>");
        if(myLayout > sortCount){sortCount = myLayout;$j('#listnext').val(sortCount);}//alert("Found: "+sortCount);
        }); //end of ucp_briefcase-layout.php
       $j('#msgBody').html("Your book has been successfully added to the "+mySemister+" Semister of "+myYear+".");
       $j(hideUnMe).hide();
       setTimeout(function(){disablemsgBoxPopup();}, 3000);
      }// end of ucp_briefcase-addnew.php pass check
      else {$j('#msgBody').html("Whoa! Lost the book! Someone dropped it on the way. Please Try again.");}


    });//end of ucp_briefcase-addnew.php


  //return false;          
  }));//emd of add2sort





 }// end of ucp_briefcase-cat_title.php pass check
 else {$j('#msgBody').html("Whoa! Lost the book! Someone dropped it on the way. Please Try again.");}

});//end ucp_briefcase-cat_title.php });//end booksort