By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,912 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,912 IT Pros & Developers. It's quick & easy.

Why the Ajax code below in ajax.js is causing my form not to work ?

P: 5
Why the Ajax code below in ajax.js is causing my form not to work ?

ajax.js:

Expand|Select|Wrap|Line Numbers
  1. var a=0;
  2. var b=0;
  3. var c=0;
  4. var d=0;
  5. var e=0;
  6. var f=0;
  7.  
  8. function check1()
  9.   {
  10.      if (document.getElementById("text1").value == "")
  11.      {
  12.       a=0; 
  13.       document.getElementById("alert1").style.visibility="visible";
  14.      }
  15.      else
  16.      {
  17.       a=1;
  18.       document.getElementById("alert1").style.visibility="hidden";
  19.      }
  20.   }
  21.  
  22. function check2()
  23.   {
  24.    if (document.getElementById("text2").value == "")
  25.      {
  26.       b=0;
  27.       document.getElementById("alert2").style.visibility="visible" 
  28.      }
  29.      else
  30.      {
  31.       b=1;
  32.       document.getElementById("alert2").style.visibility="hidden";
  33.      }
  34.   }
  35.  
  36. function check3()
  37.   {
  38.     if (document.getElementById('text3').value == "")
  39.      {
  40.       document.getElementById("alert3").style.visibility="visible";
  41.       c=0; 
  42.      }
  43.      else
  44.      {
  45.        document.getElementById("alert3").style.visibility="visible";
  46.        c=1;   
  47.      }
  48.   }
  49.  
  50. function check4()
  51.   {
  52.     if (document.getElementById('text4').value == "")
  53.      {
  54.       document.getElementById("alert4").style.visibility="visible";
  55.       d=0;
  56.      }
  57.      else
  58.      {
  59.       document.getElementById("alert4").style.visibility="hidden";
  60.       d=1;
  61.      }
  62.   }
  63.  
  64. function check5()
  65.   {
  66.      if (document.getElementById('text5').value == "")
  67.      {
  68.       document.getElementById("alert5").style.visibility="visible";
  69.       e=0;  
  70.      }
  71.      else
  72.      {
  73.       document.getElementById("alert5").style.visibility="hidden";
  74.       e=1;
  75.      }
  76.   }
  77.  
  78. function check6()
  79.   {
  80.      if (document.getElementById('text6').value == "")
  81.      {
  82.       document.getElementById("alert6").style.visibility="visible";
  83.       f=0; 
  84.      }
  85.      else
  86.      {
  87.        if (document.getElementById('text6').value==document.getElementById('text5').value)
  88.        {
  89.        document.getElementById("alert6b").style.visibility="hidden";
  90.        f=1; 
  91.        }
  92.        else
  93.        {
  94.        document.getElementById("alert6b").style.visibility="visible";
  95.        f=-1;
  96.        }   
  97.      }
  98.   }
  99.  
  100. var xmlHttp;
  101. var xmlHttp2;
  102.  
  103. function GetXmlHttpObject()
  104. {
  105. var xmlHttp=null;
  106. var xmlHttp2=null;
  107. try
  108.   { 
  109.   // Firefox, Opera 8.0+, Safari
  110.   xmlHttp=new XMLHttpRequest();
  111.   xmlHttp2=new XMLHttpRequest();
  112.   }
  113. catch (e)
  114.   {
  115.   // Internet Explorer
  116.   try
  117.     {
  118.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  119.     xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
  120.     }
  121.   catch (e)
  122.     {
  123.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  124.     xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
  125.     }
  126.   }
  127. return xmlHttp;
  128. return xmlHttp2;
  129. }
  130.  
  131. function checkUsername(str)
  132. {
  133. if (str.length==0)
  134.   { 
  135.   document.getElementById("alert4").style.visibility="visible";
  136.   return;
  137.   }
  138. else
  139.   {
  140. document.getElementById("alert4").style.visibility="hidden";
  141. xmlHttp=GetXmlHttpObject()
  142. if (xmlHttp==null)
  143.   {
  144.   alert ("Your browser does not support AJAX!");
  145.   return;
  146.   }
  147. var url="username.php";
  148. url=url+"?q="+str;
  149. url=url+"&sid="+Math.random();
  150. xmlHttp.onreadystatechange=stateChanged();
  151. xmlHttp.open("GET",url,true);
  152. xmlHttp.send(null);
  153. }
  154.  
  155. function stateChanged() 
  156. if (xmlHttp.readyState==4)
  157. document.getElementById("alertuse").innerHTML=xmlHttp.responseText;
  158. }
  159. }
  160.  
  161. function signup(stra, strb, strc, strd, stre)
  162. {
  163. xmlHttp2=GetXmlHttpObject()
  164. if (xmlHttp2==null)
  165.   {
  166.   alert ("Your browser does not support AJAX!");
  167.   return;
  168.   } 
  169. var url2="signingup.php";
  170. url2=url2+"?a="+stra+"?b="+strb+"?c="+strc+"?d="+strd+"?e="+stre"?f="+a+"?g="+b+"?h="+c+"?i="+d+"?f="+e;
  171. xmlHttp2.onreadystatechange=stateChanged2;
  172. xmlHttp2.open("GET",url2,true);
  173. xmlHttp2.send(null);
  174.  
  175. function stateChanged2() 
  176. if (xmlHttp2.readyState==4)
  177. document.getElementById("www").innerHTML=xmlHttp2.responseText;
  178. }
  179. }
  180.  
this is the form:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title></title>
  4. <script src="ajax.js" type="text/javascript"></script>
  5. </head>
  6. <body>
  7. <label for=first id=first>First Name :</label> <input type="text" id="text1" onchange="check1();" />
  8. <span id="alert1" style='visibility:hidden;'><< Please fill your first name in this field.</span><br><br>
  9.  
  10. <label for=last id=last>Last Name :</label> <input type="text" id="text2" onfocus="check1();" onchange="check2();" />
  11. <span id="alert2" style='visibility:hidden'><< Please fill your last name in this field.</span><br><br>
  12.  
  13. <label for=email id=email>E-mail :</label> <input type="text" id="text3" onfocus="check1(), check2();" onchange="check3();" />
  14. <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>
  15.  
  16. <label for=username id=username>Username :</label> <input type="text" id="text4" onfocus="check1(), check2(), check3();" />
  17. <span id="alert4" style='visibility:hidden'><< Please fill your desired username in this field.</span>
  18. <span id="alert4b" style='visibility:hidden'><< Username taken. Please choose another username.</span><br><br>
  19.  
  20. <label for=pass id=pass>Password :</label> <input type="password" id="text5" onfocus="check1(), check2(), check3(),   checkUsername(document.getElementById('text4').value);" onchange="check5();" />
  21. <span id="alert5" style='visibility:hidden'><< Please fill your desired password in this field.</span><br><br>
  22.  
  23. <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>
  24. <span id=alertuse></span> <span id=www></span>
  25. <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);" />
  26.  
  27.  
  28. <div id=confirm style='visibility:hidden;'>
  29. Please enter the confirmation code in the box below.<br><br>
  30. Confirmation Code: <input type="text" name="ccode" />  <input type="button" value="Confirm" onclick=''/>
  31. </div>
  32.  
  33. </body>
  34. </html>
pls help...
Aug 5 '07 #1
Share this Question
Share on Google+
8 Replies


dmjpro
100+
P: 2,476
Welcome to TSDN ...

u did a little bit of mistake ..

change this line ....

Expand|Select|Wrap|Line Numbers
  1. //xmlHttp.onreadystatechange=stateChanged();  === this one is error
  2. xmlHttp.onreadystatechange=stateChanged; //This one is correct
  3. //It takes the function reference .....................
  4.  
  5.  
best of luck .. neway happy frndship day!!!
Aug 5 '07 #2

P: 5
it still doesn't work...why
Aug 5 '07 #3

P: 5
happy friendship day, everybody...
Aug 5 '07 #4

dmjpro
100+
P: 2,476
it still doesn't work...why
Update the stateChange as given below ... then see what happens

Expand|Select|Wrap|Line Numbers
  1. function stateChanged() 
  2. alert('ABCDE' + xmlHttp.readyState);
  3. if (xmlHttp.readyState==4)
  4. {
  5. alert('FGHIJ'+xmlHttp.status);
  6. //document.getElementById("alertuse").innerHTML=xmlHttp.responseText;
  7. }
  8. }
  9.  
Aug 5 '07 #5

P: 5
nothing happens...i dunno what's wrong
Aug 5 '07 #6

dmjpro
100+
P: 2,476
nothing happens...i dunno what's wrong
means u r not getting any alert boxes???
Aug 5 '07 #7

P: 5
yes...i don't get any alert boxes
Aug 5 '07 #8

dmjpro
100+
P: 2,476
yes...i don't get any alert boxes

try to trace by giving alert boxes or catch the exception by try catch bolck up to where ur code is executing ...
Aug 5 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.