I'm having an issue with Javascript executing things in an order that doesn't make sense to me.
What is happening is the following
var bValid = false;
alert(bValid + " 1");
if(validateForm() == TRUE)
{
$.get("submit_manageUsers.php",
{action: sendAct, userID: userID},
function(responseText)
{
if(responseText == "GOOD")
{
alert("Update Successful");
bValid = true;
alert(bValid + " 2");
}
else
{
alert(responseText + "\n Update Unsuccessful");
bValid = false;
}
},
"html"
);
bvalid = true;
alert(bValid + " 3");
}
alert(bValid + " 4");
if(bValid == true)
{
//do something
}
alert(bValid + " 5");
EDIT: added a bit more of what is actually happening in case it helps, probably will knowing how I do things!
The output from the above code looks like this:
false 1
false 2
false 4
false 5
true 3.
The problem here is that the if(bValid == true) is being executed before the if(validateForm() == TRUE) so this means bValid is always false.
Why is that part of the code executing before the other part?
Any help on this is greatly appreciated!
TRUEis not defined, the code will just fail and does not produce any further output. If it is defined, the output will be different. From my point of view, the order of output is impossible.alert(bValid + " 2")is in your ajax callback function!!!!