Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2007, 11:29 PM   PM User | #1
Frates
New to the CF scene

 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Frates is an unknown quantity at this point
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
Frates is offline   Reply With Quote
Old 10-12-2007, 02:19 AM   PM User | #2
BarrMan
Senior Coder

 
BarrMan's Avatar
 
Join Date: Feb 2005
Location: Israel.
Posts: 1,644
Thanks: 69
Thanked 83 Times in 82 Posts
BarrMan is on a distinguished road
Code:
xmlHttp.onreadystatechange=stateChanged();
Shouldn't you give a value to the containerid to the function parameter?
BarrMan is offline   Reply With Quote
Old 10-12-2007, 04:18 AM   PM User | #3
A1ien51
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
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Old 10-12-2007, 03:07 PM   PM User | #4
Frates
New to the CF scene

 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Frates is an unknown quantity at this point
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
Frates is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:04 AM.


Advertisement
Log in to turn off these ads.