Help with JavaScript

A

akwarisk

When I try to run this web page, it says I have an error on my <Select
name="customer" onchange="showcustomer(this.value)"> line. Here is
the error I get:

Line: 57
Char: 1
Error: Object expected
Code:0
URL: http://akwarisk.brinkster.net/W3Schools/ajaxinline.html

Can anyone shed some light on what I might be doing wrong...the code
is posted below but the direct link is above.

<html>
<head>
<script type="text/javascript" language=Javascript>
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();
alert("test")
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;
}
</script>
</head>

<body>

<form>
Select a customer:
<Select name="customer" onchange="showcustomer(this.value)">
<option value="ALFKI">Alfreds Futterkiste</option value>
<option value="NORTS ">North/South</option value>
<option value="WOLZA">Wolski Zajazd</option value>
</select>
</form>

<p>
<div id="txtHint"><b>Customer info will be listed here.</b></div>
</p>

</body>
</html>
 
J

Joost Diepenmaat

When I try to run this web page, it says I have an error on my <Select
name="customer" onchange="showcustomer(this.value)"> line. Here is
the error I get:

Select boxes don't have a value. You want something like:

onchange="showcustomer(this.options[this.selectedIndex].value)"
 
G

Gregor Kofler

(e-mail address removed) meinte:
When I try to run this web page, it says I have an error on my <Select
name="customer" onchange="showcustomer(this.value)"> line. Here is
the error I get:

Line: 57
Char: 1
Error: Object expected
Code:0
URL: http://akwarisk.brinkster.net/W3Schools/ajaxinline.html

No it says: Get a decent browser.


Perhaps
function showCustomer(str){ ^
<Select name="customer" onchange="showcustomer(this.value)">
^
will already do the trick. Anyway, why are you randomly omitting the
terminating semicolon?

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top