title: jQuery datepicker issue via ajax
body: <p>I have an issue with the date picker, for some reason on first load datepicker works fine and lets me pick the date, but when I click on refresh (via ajax), the datepicker area is refreshed but then i am unable to use the datepicker. Is their anyway around it?</p>
  
  <p>Ive tried using different id and removing the old element with not much success :/</p>
  
  <p>I have a function in php that displays date, in file 'datefunction.php'</p>
  
  <pre><code>    function getDateInfo()
  {
       $date = $_GET['date'];
  
       $html = '&lt;script&gt; 
          $(document).load(function() {
          $("#dt").datepicker(\'destroy\');
          $("#dt").remove();
  
          var mydate = $("#dt1").datepicker({ dateFormat: "dd-mm-yy" });
                  $("#dt1").click(function(){
                       mydate.datepicker("show");
                       });     
                  });
              });&lt;/script&gt;
                  &lt;label&gt;Date1:&lt;/label&gt;
            &lt;input type="text" name="dt"  id="dt1" maxlength="10" size="12" value="' . $date . '" readonly="true" /&gt;';
  
       return $html;
  }
  
  echo getDateInfo();
  </code></pre>
  
  <p>I have page that is viewed called 'dates.php'</p>
  
  <pre><code>&lt;script src="/script/jquery.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type='text/javascript' src='/script/jquery-ui-1.8.9.custom.min.js'&gt;&lt;/script&gt;
  &lt;script type='text/javascript' src='/script/jquery.datePicker.js'&gt;&lt;/script&gt;
  &lt;script&gt;
  var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)
  var bustcacheparameter="";
  
  function ajaxpage(url, containerid, requesttype){
      var page_request = false
      if (window.XMLHttpRequest) // if Mozilla, Safari etc
          page_request = new XMLHttpRequest()
      else if (window.ActiveXObject){ // if IE
          try {
              page_request = new ActiveXObject("Msxml2.XMLHTTP")
          } 
          catch (e){
              try{
                  page_request = new ActiveXObject("Microsoft.XMLHTTP")
              }
              catch (e){}
          }
      } else  return false
      page_request.onreadystatechange=function(){
          loadpage(page_request, containerid)
      }
  
      if (requesttype=='get'){
          if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&amp;"+new Date().getTime() : "?"+new Date().getTime()
          page_request.open('GET', url+bustcacheparameter, true)
          page_request.send(null)
      } else if (requesttype=='post') {
          var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) + "&amp;mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
          page_request.open('POST', url, true);
          page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          page_request.setRequestHeader("Content-length", parameters.length);
          page_request.setRequestHeader("Connection", "close");
          page_request.send(parameters);
      };
  }
  
  function loadpage(page_request, containerid){
      if (page_request.readyState == 4 &amp;&amp; (page_request.status==200 || window.location.href.indexOf("http")==-1))
      document.getElementById(containerid).innerHTML=page_request.responseText
  }
  $(document).ready(function() {
                  var mydate = $("#dt").datepicker({ dateFormat: "dd-mm-yy" });
                  $("#dt").click(function(){
                       mydate.datepicker("show");
                       });     
                  });
  &lt;/script&gt;
  
  
  &lt;?php 
  $date = "05-06-2009";
  echo "&lt;div id='datearea'&gt;&lt;label&gt;Date:&lt;/label&gt;
            &lt;input type='text' name='dt' id='dt' maxlength='10' size='12' value='" . $date . "' readonly='true' /&gt;&lt;/div&gt;";
  echo "&lt;a href='#' onclick='javascript:ajaxpage(\"datefunction.php?date=02-04-1999\", \"datearea\", \"get\");'&gt;update&lt;/a&gt;";
  ?&gt;
  </code></pre>