473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
8 2086
dmjpro
2,476 2GB
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
jd2007
5
it still doesn't work...why
Aug 5 '07 #3
jd2007
5
happy friendship day, everybody...
Aug 5 '07 #4
dmjpro
2,476 2GB
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
jd2007
5
nothing happens...i dunno what's wrong
Aug 5 '07 #6
dmjpro
2,476 2GB
nothing happens...i dunno what's wrong
means u r not getting any alert boxes???
Aug 5 '07 #7
jd2007
5
yes...i don't get any alert boxes
Aug 5 '07 #8
dmjpro
2,476 2GB
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

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

Similar topics

1
by: mflll | last post by:
I am having trouble getting my simple AJAX program to work at my current University. Here is one of the programs that is giving problems. I tried it in and Mozilla/5.0 Gecko/20050923 under...
9
by: RBM007 | last post by:
Hello, I have created some pages in the (old) Atlas pages and migrated to AJAX version. After the update I noticed that any page containing ASP.NET AJAX won't compile anymore. Even if the same...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
0
by: BlipBlip | last post by:
Hi All, I was not sure which forum to post the message to since the problem related to ASP/AJAX, but decided to post it here. I have a simple routine which utilizes an Ajax to query database for...
1
by: jborg | last post by:
I have a method to send PHP array values via Ajax to another PHP file that processes my request, however I cannot get it to work here. I know this is normally a basic and very general error, but...
12
by: colt28 | last post by:
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't...
4
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.