Problems running Ajax sample

A

Angus

Hello

I am running this example from http://www.w3schools.com/ajax/ajax_server.asp

<html><body>
<script type="text/javascript">function ajaxFunction()
{ var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari xmlHttp=new
HttpRequest(); }
catch (e)
{ // Internet Explorer try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new
ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!");
return
false; } } }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null); }
</script>
<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></body>
</html>

I have IIS setup and working fine on my PC and time.asp is like this:

<%
response.expires=-1
response.write(time)
%>

But when I try to move cursor from the textboxes I get a script error:

Line: 26
Char: 1
Error: Object expected
Code: 0
URL: http://127.0.0.1/testAjax.htm

line 26 is onkeyup="ajaxFunction();" name="username" />

Anyone any ideas on how to get this working?

Angus
 
E

Evertjan.

Angus wrote on 10 apr 2007 in comp.lang.javascript:
document.myForm.time.value=xmlHttp.responseText;
But when I try to move cursor from the textboxes I get a script error:

Line: 26
Char: 1
Error: Object expected
Code: 0
URL: http://127.0.0.1/testAjax.htm

line 26 is onkeyup="ajaxFunction();" name="username" />

Could be that "time" is a reserved name.
document.myForm.time.value =

try:

document.forms['myForm'].elements['time'].value =

or try:

onkeyup="ajaxFunction(this);"
and
ajaxFunction(elem){
................
elem.form.elements['time'].value =
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top