Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Datepicker not working after $.post
    primarykey
    data
    text
    <p>I have looked through dozens of similar questions, but none of the answers given have worked. I am calling an HTML form via $.post, and there is a datepicker field in this form. I have been reading as much as I can about .live (deprecated) and .on to attempt to make the returned form live in the DOM - but have not been able to get it working properly.</p> <p>This is how I am calling the form now:</p> <pre><code>$(".projectListHead").on('click', function() { var thisId = '12'; $.post('/admin/ajax/projects/manage.php', { id: thisId }, function(data) { $("#addEditArea").html(data) }); }); </code></pre> <p>I also tried:</p> <pre><code>$("body").on('click', ".projectListHead", function() { var thisId = '12'; $.post('/admin/ajax/projects/manage.php', { id: thisId }, function(data) { $("#addEditArea").html(data); $(".datepicker").datepicker(); }); }); </code></pre> <p>This also did not work.</p> <p>This is the <code>datepicker</code> input field in the form returned in 'data':</p> <pre><code>&lt;input type="text" class="datepicker" id="datePickThis" /&gt; </code></pre> <p>And the script selecting the <code>datepicker</code> field:</p> <pre><code>$(".datepicker").datepicker(); </code></pre> <p>** UPDATE **</p> <p>I tried a suggestion that made perfect sense, and worked in JSFiddle, but would not work:</p> <pre><code>$(".projectListHead").click(function() { var thisId = '12'; $.post('/admin/ajax/projects/manage.php', { id: thisId }, function(data) { $("#addEditArea") .html(data) .find('.datepicker') .datepicker(); }); }); </code></pre> <p>but this example works if I simply override the .html value like this:</p> <pre><code>$(".projectListHead").click(function() { var thisId = '12'; $.post('/admin/ajax/projects/manage.php', { id: thisId }, function(data) { $("#addEditArea") .html('&lt;input type="text" class="datepicker" id="datePickThis" /&gt;') .find('.datepicker') .datepicker(); }); }); </code></pre> <p>Also, I know it's long but here is the entirety of the HTML I am calling back. Maybe the problem lies here:</p> <pre><code>&lt;!-- PROJECT INFORMATION HEADER ---------&gt; &lt;div class="projManHeader"&gt; &lt;div class="clientPhoto" style="background-image: url(/admin/customers/images/4_thumb.jpg);"&gt;&lt;/div&gt; &lt;div class="projectInfo"&gt; &lt;h1&gt;William Richards&lt;/h1&gt; &lt;h2&gt;Family Portraits&lt;/h2&gt; &lt;span style="font-size: 13px;"&gt;at Davis Arboretum&lt;/span&gt; &lt;/div&gt; &lt;div class="projectDateInfo"&gt; &lt;h1&gt;July 19th&lt;/h1&gt; &lt;h2&gt;6:30 PM&lt;/h2&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- NAVIGATION ICON MENU ------&gt; &lt;!-- PRELOAD IMAGE DIV ----&gt; &lt;div style="display: none"&gt; &lt;img src="/images/icons/megaphone_over.gif" /&gt; &lt;img src="/images/icons/infocircle_over.gif" /&gt; &lt;img src="/images/icons/staffcircle_over.gif" /&gt; &lt;img src="/images/icons/paycircle_over.gif" /&gt; &lt;/div&gt; &lt;div class="projectIconsContainer"&gt; &lt;div id="comIcon" class="comIcon"&gt;&lt;/div&gt; &lt;div class="sectionHeader"&gt; &lt;span style="font-weight: bold;"&gt;Contact&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size: 9px;"&gt;Email Sent&lt;br /&gt; on Aug 31, 2013 &lt;/span&gt; &lt;/div&gt; &lt;div class="infoCircleIcon"&gt;&lt;/div&gt; &lt;div class="sectionHeader"&gt; &lt;span style="font-weight: bold;"&gt;Project Info&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size: 9px;"&gt;Email Sent&lt;br /&gt; on Aug 31, 2013 &lt;/span&gt; &lt;/div&gt; &lt;div class="staffCircleIcon"&gt;&lt;/div&gt; &lt;div class="sectionHeader"&gt; &lt;span style="font-weight: bold;"&gt;Staff&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size: 9px;"&gt;Shooter:&lt;br /&gt; Leah Parker &lt;/span&gt; &lt;/div&gt; &lt;div class="payCircleIcon"&gt;&lt;/div&gt; &lt;div class="sectionHeader"&gt; &lt;span style="font-weight: bold;"&gt;Payments&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size: 9px;"&gt;Cost:&lt;br /&gt; $160.00 &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- END NAVIGATION ICON MENU --&gt; &lt;!-- BEGIN AJAX FILL AREA ------&gt; &lt;div id="ajaxFillArea"&gt;&lt;/div&gt; &lt;!---- END AJAX FILL AREA -----&gt; &lt;!-- BEGIN HIDDEN COMMUNICATION DIV -----&gt; &lt;div id="hiddenComDiv" style="display:none;"&gt; &lt;div style="padding: 15px; display: inline-block; vertical-align: middle;"&gt; &lt;h2&gt;Communication&lt;/h2&gt; &lt;/div&gt; &lt;div style="display: inline-block; float: right; vertical-align: middle; margin-top: 13px; margin-right: 30px;"&gt; &lt;input type="button" id="newComButton" value="NEW COMMUNICATION" /&gt; &lt;/div&gt;&lt;br /&gt; &lt;div id="newComForm" style="display: none;"&gt; &lt;div style="padding: 15px; width: 600px; min-height: 300px; background-color: #f0f0f0; border: solid 1px #ccc;"&gt; &lt;div style="padding: 5px; width: 100px; display: inline-block; text-align: right;"&gt;Send Email:&lt;/div&gt; &lt;div style="padding: 5px; display:inline-block;"&gt; &lt;input type="text" name="comEmailSubject" style="width: 430px;" placeholder="email subject here" /&gt; &lt;/div&gt;&lt;br /&gt; &lt;div style="padding: 5px; width: 100px; display: inline-block; text-align: right;"&gt;Message:&lt;/div&gt; &lt;div style="padding: 5px; display:inline-block; vertical-align: top;"&gt; &lt;textarea name="comEmailMessage" style="width: 430px; height: 110px;" placeholder="email message here" &gt;&lt;/textarea&gt; &lt;/div&gt;&lt;br /&gt; &lt;div style="padding: 5px; width: 100px; display: inline-block; text-align: right;"&gt;Notes:&lt;/div&gt; &lt;div style="padding: 5px; display:inline-block; vertical-align: top;"&gt; &lt;textarea name="comEmailNotes" style="width: 430px; height: 50px;" placeholder="followup / notes go here" &gt;&lt;/textarea&gt; &lt;/div&gt;&lt;br /&gt; &lt;div style="padding: 5px; width: 100px; display: inline-block; text-align: right;"&gt;&lt;/div&gt; &lt;div style="padding: 5px; display:inline-block; vertical-align: top;"&gt; &lt;input type="text" class="datepicker" id="datePickThis" /&gt; &lt;input type="button" value="SEND" /&gt; &lt;input type="button" value="CANCEL" /&gt; &lt;/div&gt;&lt;br /&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- HIDDEN COMMUNICATION DIV JQUERY --------&gt; &lt;script&gt; $(document).ready(function() { // NEW COMMUNICATION FORM $("#newComButton").click(function() { $("#newComForm").slideDown(function() { $("input[name=comEmailSubject]").focus(); }); }); // OPEN COMMUNICATION SECTION $("#comIcon").click(function() { var hiddenHtml = $("#hiddenComDiv").html(); $("#ajaxFillArea").html(hiddenHtml); }); }); &lt;/script&gt; &lt;/div&gt; </code></pre> <p>The form returned in 'data' displays properly, but the <code>datepicker</code> simply won't work. <code>Datepicker</code> does work perfectly when not called through ajax. After three hours of digging, I'm hoping someone can clue me in here. Thanks so much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload