dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Why the Ajax code below in ajax.js causes everything on the form to not function

  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Why the Ajax code below in ajax.js causes everything on the form to not function

    Why the Ajax code below in ajax.js causes everything on my page to not function ? pls help...

    Code:
    var a=0;
    var b=0;
    var c=0;
    var d=0;
    var e=0;
    var f=0;
    
    function check1()
      {
         if (document.getElementById("text1").value == "")
         {
          a=0; 
          document.getElementById("alert1").style.visibility="visible";
         }
         else
         {
          a=1;
          document.getElementById("alert1").style.visibility="hidden";
         }
      }
    
    function check2()
      {
       if (document.getElementById("text2").value == "")
         {
          b=0;
          document.getElementById("alert2").style.visibility="visible" 
         }
         else
         {
          b=1;
          document.getElementById("alert2").style.visibility="hidden";
         }
      }
    
    function check3()
      {
        if (document.getElementById('text3').value == "")
         {
          document.getElementById("alert3").style.visibility="visible";
          c=0; 
         }
         else
         {
           document.getElementById("alert3").style.visibility="visible";
           c=1;   
         }
      }
    
    function check4()
      {
        if (document.getElementById('text4').value == "")
         {
          document.getElementById("alert4").style.visibility="visible";
          d=0;
         }
         else
         {
          document.getElementById("alert4").style.visibility="hidden";
          d=1;
         }
      }
    
    function check5()
      {
         if (document.getElementById('text5').value == "")
         {
          document.getElementById("alert5").style.visibility="visible";
          e=0;  
         }
         else
         {
          document.getElementById("alert5").style.visibility="hidden";
          e=1;
         }
      }
    
    function check6()
      {
         if (document.getElementById('text6').value == "")
         {
          document.getElementById("alert6").style.visibility="visible";
          f=0; 
         }
         else
         {
           if (document.getElementById('text6').value==document.getElementById('text5').value)
           {
           document.getElementById("alert6b").style.visibility="hidden";
           f=1; 
           }
           else
           {
           document.getElementById("alert6b").style.visibility="visible";
           f=-1;
           }   
         }
      }
      
    var xmlHttp;
    var xmlHttp2;
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    var xmlHttp2=null;
    try
      { 
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      xmlHttp2=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
    return xmlHttp2;
    }
    
    function checkUsername(str)
    {
    if (str.length==0)
      { 
      document.getElementById("alert4").style.visibility="visible";
      return;
      }
    else
      {
    document.getElementById("alert4").style.visibility="hidden";
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      }
    var url="username.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged();
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    } 
    }
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4)
    { 
    document.getElementById("alertuse").innerHTML=xmlHttp.responseText;
    }
    }
    
    function signup(stra, strb, strc, strd, stre)
    {
    xmlHttp2=GetXmlHttpObject()
    if (xmlHttp2==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
    var url2="signingup.php";
    url2=url2+"?a="+stra+"?b="+strb+"?c="+strc+"?d="+strd+"?e="+stre"?f="+a+"?g="+b+"?h="+c+"?i="+d+"?f="+e;
    xmlHttp2.onreadystatechange=stateChanged2;
    xmlHttp2.open("GET",url2,true);
    xmlHttp2.send(null);
    } 
    
    function stateChanged2() 
    { 
    if (xmlHttp2.readyState==4)
    { 
    document.getElementById("www").innerHTML=xmlHttp2.responseText;
    }
    }
    this is the form:

    Code:
    <html>
    <head>
    <title></title>
    <script src="ajax.js" type="text/javascript"></script>
    </head>
    <body>
    <label for=first id=first>First Name :</label> <input type="text" id="text1" onchange="check1();" />
    <span id="alert1" style='visibility:hidden;'><< Please fill your first name in this field.</span><br><br>
    
    <label for=last id=last>Last Name :</label> <input type="text" id="text2" onfocus="check1();" onchange="check2();" />
    <span id="alert2" style='visibility:hidden'><< Please fill your last name in this field.</span><br><br>
    
    <label for=email id=email>E-mail :</label> <input type="text" id="text3" onfocus="check1(), check2();" onchange="check3();" />
    <span id="alert3" style='visibility:hidden'><< Please fill your email in this field.</span><span id="alert3b" style='visibility:hidden'><< Your email ain't valid. Please enter a valid e-mail.</span><br><br>
    
    <label for=username id=username>Username :</label> <input type="text" id="text4" onfocus="check1(), check2(), check3();" />
    <span id="alert4" style='visibility:hidden'><< Please fill your desired username in this field.</span>
    <span id="alert4b" style='visibility:hidden'><< Username taken. Please choose another username.</span><br><br>
    
    <label for=pass id=pass>Password :</label> <input type="password" id="text5" onfocus="check1(), check2(), check3(),   checkUsername(document.getElementById('text4').value);" onchange="check5();" />
    <span id="alert5" style='visibility:hidden'><< Please fill your desired password in this field.</span><br><br>
    
    <label for=cpass id=cpass>Confirm Password :</label> <input type="password" id="text6" onfocus="check1(), check2(), check3(), check4(), check5();" /><span  id="alert6a" style='visibility:hidden'><< Please confirm your password.</span><span id="alert6b" style='visibility:hidden'><< Passwords don't match.</span><br><br>
    <span id=alertuse></span> <span id=www></span>
    <input type="submit" name="signup" value="Sign Up" onmouseover="signup(document.getElementById('text1').value,  document.getElementById('text2').value, document.getElementById('text3').value, document.getElementById('text4').value, document.getElementById('text6').value);" />
    
    
    <div id=confirm style='visibility:hidden;'>
    Please enter the confirmation code in the box below.<br><br>
    Confirmation Code: <input type="text" name="ccode" />  <input type="button" value="Confirm" onclick=''/>
    </div>
    
    </body>
    </html>

  2. #2
    Join Date
    Jul 2007
    Posts
    4
    jd2007,

    The form input type 'submit' should be input type 'button'.

    See where that leads you.

    Andy

  3. #3
    Join Date
    Aug 2007
    Posts
    1
    Hi,

    Try to change the xmlHttp.onreadystatechange=stateChanged(); as follows

    xmlHttp.onreadystatechange=function(){stateChanged();}

    It may helps you

Similar Threads

  1. Ajax within Ajax generated code
    By geekdesign in forum AJAX
    Replies: 2
    Last Post: 09-16-2007, 08:38 PM
  2. Replies: 7
    Last Post: 10-28-2002, 01:10 PM
  3. wot is CLR
    By lostguy in forum .NET
    Replies: 8
    Last Post: 04-03-2002, 07:41 PM
  4. AnimateWindow API
    By Tim Manos in forum VB Classic
    Replies: 4
    Last Post: 10-19-2001, 06:06 AM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center