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

ajax not funtioning

P: 47
i had made two ajax in one form but not functioning very well... can help me??

this is my html code

[HTML]<input name="matric" type="text" id="matric" onChange="showName(this.value)" size="15" />[/HTML]

[HTML]<select name="year" onChange="showYear(this.value)">[/HTML]

and this is my javascript

(1) this is for input type

Expand|Select|Wrap|Line Numbers
  1. <script language="showName.js">
  2.  
  3. function showName(str)
  4. xmlHttp=GetXmlHttpObject()
  5. if (xmlHttp==null)
  6.  {
  7.  alert ("Browser does not support HTTP Request")
  8.  return
  9.  }
  10. var url="getsname.php"
  11. url=url+"?k="+str
  12. url=url+"&sid="+Math.random()
  13. xmlHttp.onreadystatechange=stateChanged 
  14. xmlHttp.open("GET",url,true)
  15. xmlHttp.send(null)
  16. }
  17.  
  18. function stateChanged() 
  19. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  20.  { 
  21.  document.getElementById("ok1").innerHTML=xmlHttp.responseText 
  22.  } 
  23. }
  24.  
  25. function GetXmlHttpObject()
  26. {
  27. var xmlHttp=null;
  28. try
  29.  {
  30.  // Firefox, Opera 8.0+, Safari
  31.  xmlHttp=new XMLHttpRequest();
  32.  }
  33. catch (e)
  34.  {
  35.  //Internet Explorer
  36.  try
  37.   {
  38.   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  39.   }
  40.  catch (e)
  41.   {
  42.   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  43.   }
  44.  }
  45. return xmlHttp;
  46. }// JavaScript Document
  47.  
  48. </script>
  49.  
(2) this is for my select type

Expand|Select|Wrap|Line Numbers
  1. <script src="selectyear.js">
  2. // JavaScript Documentvar xmlHttp
  3.  
  4. function showYear(str)
  5. xmlHttp=GetXmlHttpObject()
  6. if (xmlHttp==null)
  7.  {
  8.  alert ("Browser does not support HTTP Request")
  9.  return
  10.  }
  11. var url="getyear.php"
  12. url=url+"?q="+str
  13. url=url+"&sid="+Math.random()
  14. xmlHttp.onreadystatechange=stateChanged 
  15. xmlHttp.open("GET",url,true)
  16. xmlHttp.send(null)
  17. }
  18.  
  19. function stateChanged() 
  20. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  21.  { 
  22.  document.getElementById("txtHint2").innerHTML=xmlHttp.responseText 
  23.  } 
  24. }
  25.  
  26. function GetXmlHttpObject()
  27. {
  28. var xmlHttp=null;
  29. try
  30.  {
  31.  // Firefox, Opera 8.0+, Safari
  32.  xmlHttp=new XMLHttpRequest();
  33.  }
  34. catch (e)
  35.  {
  36.  //Internet Explorer
  37.  try
  38.   {
  39.   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  40.   }
  41.  catch (e)
  42.   {
  43.   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  44.   }
  45.  }
  46. return xmlHttp;
  47. }
  48. </script>
Sep 25 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 392
Can you explain what you mean by "but not functioning very well"? What specifically is doing or not doing? What steps have you taken to trouble shoot the problem.
Sep 25 '08 #2

P: 47
never mind.. it's working already..thanks
Sep 26 '08 #3

acoder
Expert Mod 15k+
P: 16,027
It's good to see that you got it working, but can you also post the solution for the benefit of others.
Sep 26 '08 #4

Post your reply

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