Jump to content

Trouble with calling function twice


Recommended Posts

Hey there. so i've tried my hardest to figure out this problem on my own but haven't been able to.  I beg anyone with info for help.

 

I have two galleries of photos, and a drop down beside each photo allowing users to move a photo between galleries. When the drop down is changed submitGalChange() is called

//submit gallery change for a given image
function submitGalChange(imageID,dropDownID,oldGal){
dropDown = document.getElementById(dropDownID);
targetGallery=dropDown.value;
//call movephoto
httpObject = new getHTTPObject();
if(httpObject != null){
	httpObject.open("GET","movePhoto.php?newGallery="+targetGallery+"&imageID="+imageID, true);
	httpObject.send(null);
	httpObject.onreadystatechange = function(){updateGallery(targetGallery,oldGal);}
}
}

 

after the move photo php script is called (which works fine) the function updateGallery() is called onreadyStageChange

 

function updateGallery(newGallery,oldGallery){
if(httpObject.readyState == 4){
	toggleGallery(newGallery);
	toggleGallery(oldGallery);
}
}

 

this is just meant to check if ready state is at 4 before refreshing the desired galleries.

 

the galleries are refreshed with toggleGallery()

//toggle gallery display of a specific gallery
function toggleGallery(name){
spanID = document.getElementById(name);
checkboxID = name + "ID";
checkID = document.getElementById(checkboxID)

httpObject = new getHTTPObject();
if(checkID.checked == true){
	if(httpObject != null){
		httpObject.open("GET","updateGallery.php?galleryName="+name, true);
		httpObject.send(null);
		httpObject.onreadystatechange = function(){setOutput(name);}
	}
}
else{
	spanID.innerHTML = "";
}
}

 

My issue some that the second time the toggle gallery is called from updateGallery() it gets stuck at readystate 1.  I've found though that if i insert alerts into the updateGallery() the script works as desired leading me to believe that this is giving the toggle gallery script time to complete before initiating the second one.

 

how can i call this function multiple times with out running into this problem?  thank you for any help!!

 

oh and the setOutput function is this

//set output span of given page
function setOutput(id){
var output = document.getElementById(id);
if(httpObject.readyState == 4){
	output.innerHTML = httpObject.responseText;		
}
else if(httpObject.readyState == 3){
	output.innerHTML = "readystate = 3";
}
else if(httpObject.readyState == 2){
	output.innerHTML = "readystate = 2";
}
else if(httpObject.readyState == 1){
	output.innerHTML = "readystate = 1";
}
else if(httpObject.readyState == 0){
	output.innerHTML = "readystate = 0";
}
else{
	output.innerHTML = "<img src=\"images/waiting.gif\"/>";	
}
}

 

once again any help greatly appreciated!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.