Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AJAX - Error: Not Implemented

    Hi All,

    I am having problems with AJAX. Hopefully someone out there has a solution. I have a classic asp program where I am trying to populate a 2nd drop down list based on the first one. However, when I try this i get an error that merely say "not implemented". Below I've trimmed down the code.


    Here is the code in the asp program:
    <tr>
    <td>Agent:</td>
    <td>
    <Select name="selAgent" onChange='JavaScript:GetAName (this.value,"selectAgentName");'>
    <%for x = 0 to nbrAgent%>
    <option value="<%=arrAgent(0,x)%>"><%=arrAgent(1,x)%></option>
    <%next%>
    </select>
    </td>
    <td>Name</td>
    <td id="selectAgentName"></td>
    </tr>


    Following is the GetAName javascript:

    var xmlHttp
    var DropDownContainer
    function GetAName(str,containerid){
    DropDownContainer=containerid;
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
    }
    var url="GetAgentName.asp";
    url=url+"?AN="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged();
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    } // end function DupSSN

    function stateChanged(containerid){
    alert(DropDownContainer + " - " + xmlHttp.readyState);
    if (xmlHttp.readyState==4){
    //alert(xmlHttp.responseText);
    document.getElementById(DropDownContainer).innerHTML=xmlHttp.responseText;
    }
    } // end functon stateChanged

    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;
    } // end function GetXmlHttpObject


    Following is the GetAgentName.asp

    <%
    Dim AgentNumber
    Dim sqlAN, rsAN, arrAN, x, nbrAN

    AgentNumber = trim(request("AN")

    sqlAN = "Select AgentNameNbr, AgentName " & _
    "From AgentName " & _
    "Where AgentNbr = '" & AgentNumber & "' " & _
    "Order by AgentName"
    Set rsAN = Conn.execute(sqlAN)
    arrAN = rsAN.getrows
    nbrAN = UBOUND(arrAN,2)

    rsAN.close
    Set rsAN = Nothing

    response.write "<Select name=selAgentName>"
    response.write "<option value=-1></option>"
    for x = 0 to nbrAN
    response.write "<option value=" & arrAN(0,x) & ">" & arrAN(1,x) & "</option>"
    next
    response.write "</select>"
    %>


    The alert in the function statechanged will give me the ID of the field and 0 as the value of the readyState. I have verifed that the GetNameAgent.asp does work by running the program in I.E. (ver 7). I know it must be something that I am doing. Any Help would be appreciative.

    TIA,
    Frates

  • #2
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Code:
    xmlHttp.onreadystatechange=stateChanged();
    Shouldn't you give a value to the containerid to the function parameter?

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    xmlHttp.onreadystatechange=stateChanged();

    should be

    xmlHttp.onreadystatechange=stateChanged;

    when you use () that means to execute the code right here and now. You want to assign the reference to the function to the evet handler.

    Since you are using a global variable to hold the xmlHttpRequest Object, you should use a global variable for the containerId.

    Also the code should be

    open
    onreadystatechange
    send

    It gets around some browser bugs.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BarrMan, thanks for you input. I did have that at one time, but read on a website that that function could not accept parameters. The website didn't say why, but i gave it a try. After i passed the id value to the function GetAName I put it in a global variable.

    Eric, I owe you a Big Thank You. It worked !!! Took the () off and rearranged the code as you said. Works Great !!! Thanks !!!

    Frates


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •