Hi,
I am working on database part using ajax,javascript and asp.
I'm getting Object Expected error at line 6.

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<script src="selectCustomer.js" language="javascript" type="text/javascript"></script>
<form action="javascript: void 0;" method="post" name="form1" id="form1" >
select a customer:
<select name="customers" onchange="showCustomer()">
<option value="ALFKI">Alfreds Futterkiste
<option value="NORTS ">North/South
<option value="WOLZA">Wolski Zajazd 
</select>
</form>
<p>
<div id="txtHint" ><b> customer info will be listed here</b></div>
</p>
</body>
</html>

i tried but didnt get any results.
Plz help me regarding this

where is js code......

where is js code......

this is the js code:

selectCustomer.js

var xmlHttp

function showCustomer(str)
{
xmlHttp=GetXmlHttpobject();
if(xmlHttp==null)
{
 alert('your browser does not support ajax!!');
 return;
 }
 
 var url="getcustomer.asp";
 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)
 {
 document.getElementById("txtHint").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;
}

This is the asp code to connect to database: getcustomer.asp:

<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"

set con=Server.CreateObject("ADODB.Connection")
con.ConnectionString = "DSN=Ajax"
con.Open
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn

response.write("<table>")
do until rs.EOF
  for each x in rs.Fields
    response.write("<tr><td><b>" & x.name & "</b></td>")
    response.write("<td>" & x.value & "</td></tr>")
  next
  rs.MoveNext
loop

response.write("</table>")
%>

Hi

in javascript code two modification is needed:
1.

function showCustomer(str)
{
xmlHttp=GetXmlHttpobject();  //error  it is GetXmlHttpObject();
if(xmlHttp==null)
...............
}

2. define function GetXmlHttpObject(); before calling it i.e. before showCustomer();
u cannot call a function until unless it is not defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.