473,761 Members | 8,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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 2122
dmjpro
2,476 Top Contributor
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 New Member
it still doesn't work...why
Aug 5 '07 #3
jd2007
5 New Member
happy friendship day, everybody...
Aug 5 '07 #4
dmjpro
2,476 Top Contributor
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 New Member
nothing happens...i dunno what's wrong
Aug 5 '07 #6
dmjpro
2,476 Top Contributor
nothing happens...i dunno what's wrong
means u r not getting any alert boxes???
Aug 5 '07 #7
jd2007
5 New Member
yes...i don't get any alert boxes
Aug 5 '07 #8
dmjpro
2,476 Top Contributor
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
2143
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 Fedora Linux I see the alert's "V" and "V Two" The latter says "null.firstChild.data; yy = YYNode.firstChild.data; document.QQ.xxReceive.value = xx;
9
2143
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 tags and properties are used in a page without a masterpage. Does anyone shares this exprerience with me or does anyone knows an answer? For the time being, I copy-pased the headings in my masterpage to the clield pages.
1
4033
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 technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
0
2466
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 keywords presence in database and returns matched records count. Below is the code for 2 pages. First page would take an input, post to the second via ajax and displays the returned message. Everything works fine when I use keywords contained Latin...
1
2039
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 I cannot figure out how I am getting it. I am trying to program a specific event calendar, the issue is on one of the events. I am trying to allow users to rate other users that went to the event. The below code lists the users, and attempts to...
12
3840
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 work...dunno why, but anyhow. The form appears after a delay on the page in a hidden DIV. The original form just had name, email and message, but i have to add a few questions to it so i did and i also added some code from another script i found to...
4
5358
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 text field which causes the Autocomplete extender to display 10 like items, after the users selects an item (which is a key in the database) I want the application to go to the database retrieve a record and populate the fields.
7
6669
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 tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
1
4610
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 Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.