higgsy
asked on
Execution order of javascript function
Hi,
Ive got a function that calls another function which uses the Microsoft.XMLHTTP component to fire a load of requests off to anther page. In the first function, i want to make a layer on my page visible, just telling the user not to navigate away from the page until the layer closes. My function is as so:
function CopySelected(theAction)
{
var warningLayer = document.getElementById("d ivWarning" );
warningLayer.style.visibil ity = "visible";
var controlIndex; // to hold the current ID within the loop of control objects
var element; // to hold the value of the current control
var numberOfControls = document.frmProjects.lengt h; //counts all the form elements within the current form
for (controlIndex = 0; controlIndex < numberOfControls; controlIndex++)
{
element = document.frmProjects[contr olIndex];
//check whether the current control is a checkbox
if (element.type == "checkbox")
{
if (element.checked == true)
{
//copy names to hidden fields
var theValue = element.value
var theRow = document.getElementById("r ow" + theValue);
if(theRow.className != "RedNormalText") {
if(theAction == "Close") {
theRow.className = "GreyNormalText";
} else {
theRow.className = "BlackNormalText";
}
}
var IDList = document.getElementById("h dnIDList") ;
IDList.value = IDList.value + element.value + ',';
CloseProject(theValue,theA ction);
} //end if(element.checked == true)
} //end if (element.type == "checkbox")
} //end for loop
//warningLayer.style.visib ility = "hidden";
//no need to submit the form
return false;
}
You can see in the above function that on the second line i make the layer visible, it is not for another 20 odd lines that the call to the other function is called "CloseProject(theValue,the Action);". However, the other function seems to execute before me layer is shown. Is there any way i can pause the above function until i am sure that the layer has been made visible??
Thanks in advance
Al
Ive got a function that calls another function which uses the Microsoft.XMLHTTP component to fire a load of requests off to anther page. In the first function, i want to make a layer on my page visible, just telling the user not to navigate away from the page until the layer closes. My function is as so:
function CopySelected(theAction)
{
var warningLayer = document.getElementById("d
warningLayer.style.visibil
var controlIndex; // to hold the current ID within the loop of control objects
var element; // to hold the value of the current control
var numberOfControls = document.frmProjects.lengt
for (controlIndex = 0; controlIndex < numberOfControls; controlIndex++)
{
element = document.frmProjects[contr
//check whether the current control is a checkbox
if (element.type == "checkbox")
{
if (element.checked == true)
{
//copy names to hidden fields
var theValue = element.value
var theRow = document.getElementById("r
if(theRow.className != "RedNormalText") {
if(theAction == "Close") {
theRow.className = "GreyNormalText";
} else {
theRow.className = "BlackNormalText";
}
}
var IDList = document.getElementById("h
IDList.value = IDList.value + element.value + ',';
CloseProject(theValue,theA
} //end if(element.checked == true)
} //end if (element.type == "checkbox")
} //end for loop
//warningLayer.style.visib
//no need to submit the form
return false;
}
You can see in the above function that on the second line i make the layer visible, it is not for another 20 odd lines that the call to the other function is called "CloseProject(theValue,the
Thanks in advance
Al
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
- on the onload of the new layer, set a variable X to true
- use a timeout-function to call the rest of your function
- this timeout-function should test the status of the variable X, if false then it recalls the timeout and exits, if true it continues