Hi,
First of all I’m sorry if anybody has ask about this before, and sorry if the title is wrong.
So, I use a function to call a validation function, and if the validation is good, it will continue to submit the form. I use function like below :
[CODE]function validation(frm) {
var validate = returnTable(‘HELP’);
if(validate)
document.frmCompleteOrder.submit()
else
alert(‘Error’)
return false
}
The function returnTable() is a function that use an xmlhttp procedure.
On xmlhttp.onreadystatechange, it call the validateRow() function, which is the real validation function.
I make it that way because I need to push a list of table name into array then transfer it to the validateRow() function.
[CODE]function returnTable(pre)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null) {
alert (“Your browser does not support AJAX!”);
return;
}
xmlhttp.open(“GET”,”totalTables.php?pref=”+ pre,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function () {
var msg;
if (xmlhttp.readyState == 4) {
msg = validateRow(pre)
}
if(msg)
alert(msg);
return false;
};
}
With a code like this, the ‘validate’ in first code is always undefined, and it won’t submit the form. And I think it’s because the returnTable() function is not returning anything.
How can I return the ‘msg’ in :
[CODE]xmlhttp.onreadystatechange=function () {
var msg;
if (xmlhttp.readyState == 4) {
msg = validateRow(pre)
}
if(msg)
alert(msg);
return false;
};
to returnTable() function, so the returnTable() function can return the ‘msg’ into my first function.
Any suggestions and help are very appreciated.