Hello, I'm having this huge problem trying to validate a login form using ajax.
Everything works fine, but I cant use the xml "result" tag data to validate the form. I use an "onsubmit" function to call an ajax "load" funtion that brings me the data I need, that works ok. What I cant do is to have the ajax load fuction return true or false depending on this xml result var. This is my code:

the html:
<script type="text/javascript">
function validate(){
if (!load('login.php','var=x')==0){
return false;
}
return true;
}
</script>
<form id="formLogin" name="formLogin" method="post" onsubmit="return validate();" action="home.html">
//form code
</form>


the js:
function newAjax() {
var xmlhttp=false;
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp=false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp=new XMLHttpRequest();
}
return xmlhttp;
}


function load(target,var) {
var layer=document.getElementById('msg');
var ajax=newAjax();
ajax.open("POST",target, true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send(var);
function result(){
if (ajax.readyState==4){
if (ajax.responseXML.getElementsByTagName('result')[0].firstChild.data==1){
layer.innerHTML = "bad";return false;
}else{
layer.innerHTML = "good";
return true;
}
}
}
ajax.onreadystatechange = result;
}


the .php

<?php
header('Content-type: text/xml');
$err = '';
$err .= $HTTP_POST_VARS["var"]."<br>";
$result = 1;
?>
<xmlresponse>
<result><? echo $result; ?></result>
<msg><?
echo '<![CDATA[';
echo $err;
echo ']]>';
?></mensaje>
</xmlresponse>

this programs returns "bad" or "good" depending on $result, but I cant use that to return true or false on the "load" function to validate the form. The onreadystatechange event makes the thing dificult to solve.

Any ideas...?

Please Help.