Problems running Ajax sample

Discussion in 'Javascript' started by Angus, Apr 10, 2007.

  1. Angus

    Angus Guest

    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
     
    Angus, Apr 10, 2007
    #1
    1. Advertising

  2. Angus

    Evertjan. Guest

    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 =


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 10, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jake
    Replies:
    0
    Views:
    562
  2. celoftis
    Replies:
    10
    Views:
    2,908
    Master Programmer
    Nov 21, 2006
  3. Tim Chase
    Replies:
    0
    Views:
    76
    Tim Chase
    Feb 16, 2014
  4. Terry Reedy
    Replies:
    0
    Views:
    84
    Terry Reedy
    Feb 16, 2014
  5. Tim Chase
    Replies:
    0
    Views:
    88
    Tim Chase
    Feb 16, 2014
Loading...

Share This Page