ajax not funtioning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • azura
    New Member
    • Jul 2008
    • 47

    ajax not funtioning

    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="showN ame(this.value) " size="15" />[/HTML]

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

    and this is my javascript

    (1) this is for input type

    Code:
    <script language="showName.js">
    
    function showName(str)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="getsname.php"
    url=url+"?k="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("ok1").innerHTML=xmlHttp.responseText 
     } 
    }
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     //Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }// JavaScript Document
    
    </script>
    (2) this is for my select type

    Code:
    <script src="selectyear.js">
    // JavaScript Documentvar xmlHttp
    
    function showYear(str)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="getyear.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 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("txtHint2").innerHTML=xmlHttp.responseText 
     } 
    }
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     //Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    </script>
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    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.

    Comment

    • azura
      New Member
      • Jul 2008
      • 47

      #3
      never mind.. it's working already..thanks

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        It's good to see that you got it working, but can you also post the solution for the benefit of others.

        Comment

        Working...