Results 1 to 2 of 2

Thread: Ajax Help

  1. #1
    Join Date
    Dec 2004
    Location
    Kentucky
    Posts
    32

    Ajax Help

    I'm trying to change two different IDs. One is a <textarea> and the other is an <input type="text">. I have an onchange event that has two functions, but it's only pulling the last one.

    Here is my javascript code:

    Code:
    <script type="text/javascript">
           var xmlHttp;
    
    function loadAnnouncement(str)
    { 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="loadAnnouncement.php"
    url=url+"?d="+str
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    
    }
    
    
    function loadStarttime(str)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="loadStarttime.php"
    url=url+"?st="+str
    xmlHttp.onreadystatechange=stateChanged2
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    
    }
    
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
    document.getElementById("message").value = xmlHttp.responseText;
     } 
    }
    
    
    function stateChanged2() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
    document.getElementById("starttime").value = 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>

  2. #2
    Hello,

    This has nothing to do with AJAX, the problem is trying to set a textarea's contents by assigning to ".value" doesn't work.

    A textarea has its contents in child text nodes. First you might need to clear it using this function:
    Code:
    function removeChildren(node)
    {
      while (node.firstChild)
        node.removeChild(node.firstChild)
    }
    Then append text using this:
    Code:
    function appendToTextArea(node, text)
    {
      node.appendChild(document.createTextNode(text));
    }
    Hope that helps,

    Jim
    Blue Room Hosting - High availability UK VPS
    KVM Plans - Multiple OS support. Virtual console and CD drive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •