javascript - Loading datepicker in ajax call, then onclick does not work -


i loading datepicker script in ajax call, works fine , loads datepicker should. problem having when click day not fire onclick function.

if load datepicker page on own in seperate window works fine

ajax call

function dates(str2){    var event = findselection("event");   if (str2 == "")   {     document.getelementbyid("dates").innerhtml = "";     return;   }   if (window.xmlhttprequest)   {// code ie7+, firefox, chrome, opera, safari     xmlhttp = new xmlhttprequest();   }   else   {// code ie6, ie5     xmlhttp = new activexobject("microsoft.xmlhttp");   }   xmlhttp.onreadystatechange = function()   {     if (xmlhttp.readystate == 4 && xmlhttp.status == 200)     {       document.getelementbyid("dates").innerhtml = xmlhttp.responsetext;       $("#datepicker").datepicker();     }   }     xmlhttp.open("get", "dates.php?event=" +      event + "&type=" + document.getelementbyid("type").value, true);    xmlhttp.send();  } 

dates.php

<!doctype html>  <html lang="en"> <head>   <meta charset="utf-8" />   <title>jquery ui datepicker - display inline</title>   <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />   <script src="http://code.jquery.com/jquery-1.9.1.js"></script>   <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>   <link rel="stylesheet" href="/resources/demos/style.css" />   <script>   $(function () {       $('#datepicker').datepicker({           dateformat: 'dd-mm-yy',           numberofmonths: 1,           onselect: function (selected, evnt) {               alert("i alert box!");           }       });   });      </script> </head> <body>  date: <div id="datepicker"></div>   </body> </html> 

maybe this

dates.php (remove this)

date: <div id="datepicker"></div> 

then js code (change redystate change function to):

  xmlhttp.onreadystatechange = function()   {     if (xmlhttp.readystate == 4 && xmlhttp.status == 200)     {       document.getelementbyid("dates").innerhtml = xmlhttp.responsetext;       $('#datepicker').datepicker({           dateformat: 'dd-mm-yy',           numberofmonths: 1,           onselect: function (selected, evnt) {               alert("i alert box!");           }       });     }   } 

or since youre using jquery anyway change dates function to

function dates(str2){   var event = findselection("event");   $("#dates").load("dates.php?event=" +      escape(event) + "&type=" + escape($("#type").val()));   $('#datepicker').datepicker({      dateformat: 'dd-mm-yy',      numberofmonths: 1,      onselect: function (selected, evnt) {         alert("i alert box!");      }  }); } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -