tags:

views:

61

answers:

1

Hey I am trying to run two ajax functions in the same page

One sends the value put into username the other sends the value put into email, which sends to ajax.php & ajax1.php

below is my code:

<script type="text/javascript">
function AjaxFunction(username)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{  
alert("Your browser does not support AJAX!");
return false;
}
}
}
 function stateck() 
{
 if(httpxml.readyState==4)
{
document.getElementById("msg").innerHTML=httpxml.responseText;

}
}

httpxml.onreadystatechange=stateck;
url="ajax.php?value=" + username.value;
httpxml.open("GET",url,true);
httpxml.send(null);

}


 function AjaxFunction(email)
 {
 var httpxml;
 try
 {
 // Firefox, Opera 8.0+, Safari
 httpxml=new XMLHttpRequest();
 }
 catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateck() 
{
if(httpxml.readyState==4)
 {
 document.getElementById("msg1").innerHTML=httpxml.responseText;

}
}

httpxml.onreadystatechange=stateck;
url1="ajax.php1?value=" + email.value;
httpxml.open("GET",url1,true);
httpxml.send(null);

}
</script>



<form id="form" name="form" method="post" action="">
  <p>
    <label>Username
       <input type="text" name="username" id="username" onBlur="AjaxFunction(username);">
    </label>
  <div id="msg"></div>
  <p>Email 
    <label>
       <input type="text" name="email" id="email" onBlur="email(EMAIL);">
  </label>  
   <div id="msg1"></div>
   <p>
     <label>
      <input type="submit" name="button" id="button" value="Submit">
    </label>
</form>

The response text should then be put into div tags (msg & msg1)

Thanks

+1  A: 

Have you looked into jQuery, it will greatly reduce the complexity of your page and provide a nice API for browser abstraction. I can already see cross browser issues.

zodeus
Yeh I have already looked into that. The code above "just" works...when i have got it working fully I will clean it up and fix problemsta