ajax issue, code from form isn't executed

Discussion in 'JavaScript' started by hip_hop_x, Feb 6, 2008.

  1. #1
    The form, it's because of the table? Or what's the problem that causes the data to not send? I added a function onClick.... but doesn't work :(.
    Maybe someone has a sollution for this problem.

    Btw, the html is not complete, all the id's & names are existent.
    The html page
    
    <script src="js/ajax_register.js" type="text/javascript"></script> 
    <form name="form1" id="form1"><table border="0" id="table_box">
        <tr><td width="81">Username:</td><td width="146"><input type="text" name="username" class="textfield" id="username"/></td></tr>
        <tr><td>Password:</td> <td><input type="password" name="password" class="textfield" id="password"/></td></tr>
        <tr><td>Email:</td> <td><input type="text" name="email" class="textfield" id="email"/></td></tr>
        <tr><td>Full Name:</td> <td><input type="text" name="name" class="textfield" id="name"/></td></tr>
        
        <tr><td></td><td align="right"><a href='#' id="bolded" onClick="showResult()">Create Account</a></td></tr>
        </table>
    </form>
    PHP:


    The ajax_register.js page

    var xmlHttp
    function showResult(){
    var str=document.getElementsById("username").value;
    var password=document.getElementsById("password").value;
    var email=document.getElementsById("email").value;
    var name=document.getElementsById("name").value;
    if(str.length==0){ 
     document.getElementById("result").innerHTML="";
     document.getElementById("result").style.border="0px";
     document.write("you forgot to complete all the fields");
     return
     }
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null){
     return
     } 
    var url="data.php"
    url=url+"?usr="+str
    url=url+"&cod="+password
    url=url+"&email="+email
    url=url+"&name="+name
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    } 
    function stateChanged(){ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("result").innerHTML=xmlHttp.responseText;
     document.getElementById("form1").style.display="none";
     }
    else{
     document.getElementById("lic").style.display="none";
    }
    }
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try{
     xmlHttp=new XMLHttpRequest();
     }
    catch (e){
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    PHP:

    [Solved]the main problem was the document.getElementsById
     
    hip_hop_x, Feb 6, 2008 IP