troubleshooting Question

variable being overwritten by default?

Avatar of whaleyk
whaleyk asked on
AJAX
6 Comments1 Solution225 ViewsLast Modified:
Hello experts, in the code sample below I've set a default folderID of 1.  My "folderID click function" is successfull passing the selected folderID to "inboxresults.cfm".  

However, my "next" and "previous" click functions always pass the default folderID value of 1 (and never a newly selected value).  

Can you please help me understand how to update the default value  (I thought I was by setting "var folderID = $(this).attr('data-id'); " in my ".folderID" click function.

As always, your time is appreciated.
K
<script type="text/javascript">
$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

var folderID = 1

	



$(function() {
		
	function loadMessages() {	  
 	var myInbox = "/test/inboxResults.cfm?folderID="+folderID;
	$("#messageList").load(myInbox)
	  var myFolders = "/test/folders.cfm";
	$("#mainFolders").load(myFolders)  
	}   
	
	loadMessages();
	
	$("#next").click(function() {
		var myInbox = "/test/inboxResults.cfm?folderID="+folderID;
		myInbox+="&startRow="+nextstart
		$.get(myInbox,function(data){
		$("#messageList").html(data);
	  });
	})
	
	
	$("#prev").click(function() {
		var folderID = $(this).attr('data-id'); 							  
		var myInbox = "/test/inboxResults.cfm?folderID="+folderID;
		myInbox+="&startRow="+prevstart
		$.get(myInbox,function(data){
		$("#messageList").html(data);
	  });
	})
	

	$(".folderID").click(function() {
 		var folderID = $(this).attr('data-id'); 				  
		var myInbox = "/test/inboxResults.cfm?folderID="+folderID;
		$.get(myInbox,function(data){
		$("#messageList").html(data);
	  });
	})	
})


var prevstart = 1
var nextstart = 1

function showPrev(newprevstart){
	prevstart = newprevstart
	$("#prev").show()
}

function hidePrev(){
	$("#prev").hide()
}

function showNext(newnextstart){
	nextstart = newnextstart
	$("#next").show()
}

function hideNext(){
	$("#next").hide()
}
</script>
ASKER CERTIFIED SOLUTION
HainKurt
Sr. System Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros