title: Copy/append ajax textarea response to another non-ajax textarea
body: <p>I have ajax domain lookup script.</p>
  
  <p>Look here for <a href="http://www.dotfier.com/d/" rel="nofollow noreferrer">DEMO:</a> </p>
  
  <p>Here is JS code for Ajax form Textarea1</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  //Specify the time to wait before checking
  var intervalToCheckForChange = 250; // in milliseconds, 300 = 0.3sec
  var request;
  var statusDivJS;
  var isAvailableDivJS;
  var domainInput;
  var domainsAvailableInput;
  var isInProgress = false;
  var prevCheckValue = ".com";
  var whatDomainDivJS;
  var intStartCheck;
  var isLoaded = false;
  var intFailedResponse;
  var timesError = 0;
  &lt;?php if ($allowedTLDs != null) { ?&gt;
  var allowedTLDs = new Array(&lt;?php
                  $totalSize = count($allowedTLDs);
                  for ($i = 0; $i &lt; $totalSize; $i++)
                  {
                      echo '"'.$allowedTLDs[$i].'"';
                      if ($i != ($totalSize-1)) echo ',';
                  }
                  ?&gt;  );
  &lt;?php } else { ?&gt;               
  var allowedTLDs = null;
  &lt;?php } ?&gt;
  var ajaxDomainForm;
  var showAvailableDomains = &lt;?php if (SHOW_AVAILABLE_DOMAINS) echo 'true'; else echo 'false'; ?&gt;;
  var enableCaptcha = &lt;?php if (ENABLE_RECAPTCHA) echo 'true'; else echo 'false'; ?&gt;;
  var recaptcha_text;
  function checkDomain()
  {   
      if (isInProgress) return;
      isInProgress = true;
      prevCheckValue = domainInput.value;
      if (domainInput.value.indexOf(".") &lt; 0)
      {
          statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Enter the TLD (e.g: "+domainInput.value+".COM)&lt;\/span&gt;";
          isInProgress = false;   
          return;
      }
      else if ((enableCaptcha) &amp;&amp; ((Recaptcha == null) || ((Recaptcha.get_response() == ''))))
      {
          statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Please fill in the captcha field below [ &lt;a href='#' onClick='checkDomain();return false;'&gt;Retry&lt;\/a&gt; ]&lt;\/span&gt;";
          isInProgress = false;   
          return;
      }
      else
      {
          //check whether valid extension
          extension = prevCheckValue.substr(prevCheckValue.indexOf('.')+1);
          if ((extension != '') &amp;&amp; (allowedTLDs != null))
          {
              found = false;
              for (i = 0; i &lt; allowedTLDs.length; i++)
              {
                  if (allowedTLDs[i] == extension)
                  {
                      found = true;
                      break;
                  }
              }
              if (found == false)
              {
                  statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;TLD not allowed. Only "+allowedTLDs+" TLDs allowed&lt;\/span&gt;";
                  isInProgress = false;   
                  return;
              }
          }
      }
      re = new RegExp("^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$"); 
      if (prevCheckValue.match(re) == null)
      {
          statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Invalid Domain (Letters, numbers and hypens only) &lt;\/span&gt;";
          isInProgress = false;   
          return;
      }
      statusDivJS.innerHTML = "&lt;span style='color:green;'&gt;&lt;img src='prg.gif' height='16' width='16' alt='in progress'&gt;Checking "+prevCheckValue+" [ &lt;a href='#' onClick='abortRequest();return false;'&gt;Abort&lt;\/a&gt; / &lt;a href='#' onClick='retryRequest();return false;'&gt;Retry&lt;\/a&gt; ]&lt;\/span&gt;";
      if (window.XMLHttpRequest) { // Mozilla, Safari, ...
          request = new XMLHttpRequest();
      } 
      else if (window.ActiveXObject) { // IE
          request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      recap_challenge = '';
      recap_response = '';
      &lt;?php if (ENABLE_RECAPTCHA) { ?&gt;
      recap_challenge = Recaptcha.get_challenge();
      recap_response = Recaptcha.get_response();
      if (recap_challenge == null) return;
      Recaptcha.destroy();
      recaptcha_text.style.display="none";
      &lt;?php } ?&gt;
      var requestUrl = "?aj=&amp;ma="+Math.random()+"&amp;domain="+prevCheckValue+"&amp;rc="+recap_challenge+"&amp;rr="+recap_response;
      //document.location.href = requestUrl;return;
      request.open("GET",requestUrl,true);
      request.onreadystatechange = processResponse; 
      intFailedResponse = setTimeout("failedResponse()",15000);
      try {request.send(null); }
      catch (e) 
      {
          timesError++;
          statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Error connecting to server ("+timesError+"x)&lt;\/span&gt;";    
      }
  }
  function failedResponse()
  {
      if (!isInProgress) return;
      isInProgress = false;   
      timesError++;
      statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Error connecting to server ("+timesError+"x)(&lt;a href='#' onClick='checkDomain();return false;'&gt;Retry&lt;\/a&gt;)&lt;\/span&gt;";
      request.abort();
      request = null;
  }
  function retryRequest()
  {   
      if (!isInProgress) return;
      request.abort();
      isInProgress = false;   
      request = null;
      statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Retrying&lt;\/span&gt;";
      checkDomain();
  }
  function abortRequest()
  {
      if (!isInProgress) return;
      request.abort();
      isInProgress = false;   
      request = null;
      statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;Aborted&lt;\/span&gt;";
  }
  function updateDomainTld(tldBox)
  {
      var domainText = domainInput.value;
      if (domainText.indexOf('.') == -1) return;
      domainText = domainText.substr(domainText,domainText.indexOf('.'));
      domainInput.value = domainText + "." + tldBox.value;
  }
  function processResponse()
  {   
      statusDivJS = document.getElementById("statusDiv"); 
      if (request.readyState == 4)
      {           
          clearTimeout(intFailedResponse);
          var requestXML = request.responseXML; 
          if ((requestXML != null) &amp;&amp; (typeof(requestXML) == "object") &amp;&amp; (requestXML.getElementsByTagName("domainname")[0] != null))
          {   
              statusDivJS.innerHTML = "Done (&lt;a href='#' onClick='checkDomain();return false;'&gt;Force Check&lt;\/a&gt;)";
              isInProgress = false;
              var domain = requestXML.getElementsByTagName("domainname")[0].firstChild.data;  
              var available = requestXML.getElementsByTagName("available")[0].firstChild.data;
              var errorMsg = "";
              if (requestXML.getElementsByTagName("errorMsg")[0].firstChild != null)
              {
                  errorMsg = requestXML.getElementsByTagName("errorMsg")[0].firstChild.data;
                  if (errorMsg.indexOf('Captcha') &gt; -1)
                  {
                      Recaptcha.create("&lt;?php echo RECAPTCHA_PUBLIC_KEY; ?&gt;",
                          "recaptcha_div", {
                             theme: "white",
                             callback: Recaptcha.focus_response_field
                          });
                      recaptcha_text.style.display="";
                  }
              }
              if (available == "true") 
              {
                  statusDivJS.innerHTML = "&lt;span style='color:green;'&gt;'"+domain+"' is available!&lt;\/span&gt;";
                                  available = "&lt;span style='color:green;'&gt;&lt;b&gt;YES&lt;\/b&gt;&lt;\/span&gt; ";
                  if (showAvailableDomains)
                  {
                      if (domainsAvailableInput.value.indexOf(domain +" ") == -1)
                          domainsAvailableInput.value = domainsAvailableInput.value + domain +" \n";
                  }
              }
              else
              {
                  statusDivJS.innerHTML = "'"+domain+"' is not available.";
                  available = "&lt;span style='color:red;'&gt;NO&lt;\/span&gt;";
              }
              if (errorMsg != "")
              {
                  statusDivJS.innerHTML = "&lt;span style='color:red;'&gt;"+errorMsg+"&lt;\/span&gt; [ &lt;a href='#' onClick='checkDomain();return false;'&gt;Retry&lt;\/a&gt; ]";           
              }
              if (whatDomainDivJS != null)
                  whatDomainDivJS.innerHTML = domain;
              if (isAvailableDivJS != null)
                  isAvailableDivJS.innerHTML = available;
          }
          else
          {
              failedResponse();
              return;
          }       
      }
      else if (request.readyState == 3)
      {
          statusDivJS.innerHTML = "Request sent...";
      }
  }
  function checkForChange()
  {
      if (!isLoaded) return;
      if (domainInput == null) return;
      if (domainInput.value == '') return;
      clearTimeout(intStartCheck);
      if (prevCheckValue != (domainInput.value)) 
      {
          intStartCheck = setTimeout("checkDomain()",intervalToCheckForChange);
      }
  }
  function bodyonLoad()
  {
      statusDivJS = document.getElementById("statusDiv");
      isAvailableDivJS = document.getElementById("isAvailableDiv");
      domainInput =  document.getElementById("domain");
      domainsAvailableInput = document.getElementById("domainsAvailable");
      whatDomainDivJS = document.getElementById("whatDomainDiv");
      ajaxDomainForm =  document.getElementById("ajaxDomainForm");
      &lt;?php if (ENABLE_RECAPTCHA) { ?&gt;
      Recaptcha.create("&lt;?php echo RECAPTCHA_PUBLIC_KEY; ?&gt;",
          "recaptcha_div", {
             theme: "white",
             callback: Recaptcha.focus_response_field
          });
       &lt;?php } ?&gt;
       recaptcha_text = document.getElementById('recaptcha_text');
      isLoaded = true;
      setInterval("checkForChange()",intervalToCheckForChange);
  }
  window.onload = bodyonLoad;
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is HTML code for Ajax textarea1</p>
  
  <pre><code>&lt;form onSubmit="checkDomain();return false;" id="ajaxDomainForm" action=""&gt;
  &lt;input name="domain" type="text" id="domain" style="font-size:2em; width:60%;" onKeyUp="checkForChange();" maxlength="255"&gt;
  &lt;div id='statusDiv' style="font-weight:bold"&gt;Type a domain name!&lt;/div&gt;&lt;br&gt;
  &lt;textarea name="domainsAvailableInput" cols="40" rows="7" id="domainsAvailable" readonly="readonly"&gt;&lt;/textarea&gt;
  &lt;div id='whatDomainDiv' style="font-weight:bold"&gt;Domain&lt;/div&gt;
  &lt;div id='isAvailableDiv' style="font-size:5em"&gt;?&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is HTML code for NON-Ajax Form textarea2</p>
  
  <pre><code>&lt;form id="" method="post" action="/domainchecker.php?search=bulk"&gt;
  &lt;textarea name="bulkdomains" cols="60" rows="8"&gt;&lt;/textarea&gt;
  &lt;input type="submit" id="Submit" value="Lookup"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>What I want is, Once I get ajax response from server in textarea1, Copy / append it to textarea2.</p>
  
  <p>The reason for this is I am unable to perform action within textarea1 due to limitations of domainchecker.php of form2</p>
  
  <p>How Can I achieve this ?</p>
  
  <p>Thanks.</p>
  
  <ul>
  <li>Mandar</li>
  </ul>