Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery datepicker default date
    text
    copied!<p>I am trying to get a attribute of a date picker to pull the date dynamically, however I get uncaught exception errors when I try to set it to a variable.</p> <p>The errors only occur on pages that do NOT have the calendar (inline). How can I pul the rel tag from the selector without getting this error?</p> <pre><code>//Event Calendar Home Page and Listing function calendar_picker () { $("#calendar-inline").datepicker({ //defaultDate: $(this).attr('rel'), dateformat: 'yy-mm-dd', maxDate: '+1y', minDate:'-0d', hideIfNoPrevNext: true, showButtonPanel: false, navigationAsDateFormat: false, onSelect: function(dateText, inst) { var d = new Date(dateText); var fmt1 = $.datepicker.formatDate("yy-mm-dd", d); $.ajax({ type: "POST", url: "/events/listing/all/20/", dataType: "html", date: "event_date="+fmt1, success: function(){ window.location.href= "/events/browse/"+fmt1; }});}}); } </code></pre> <p><strong>UPDATE</strong> Correct, the commented line is what I am having issues with, What is the correct way to pull the attribute rel from #calendar-inline from inside this. All attempts throw a uncaught error in js</p> <p><strong>Update 2</strong></p> <pre><code>function calendar_picker () { var myDate = new Date($("#calendar-inline").attr('rel')); $("#calendar-inline").datepicker({ dateformat: 'yy-mm-dd', defaultDate:myDate, </code></pre> <p><strong>Solution:</strong></p> <pre><code>function calendar_picker () { var myDate = null; if ($("#calendar-inline").attr('rel') != null) { myDate = $.datepicker.parseDate("yy-mm-dd", $("#calendar-inline").attr('rel')); } $("#calendar-inline").datepicker({ dateformat: 'yy-mm-dd', defaultDate:myDate, </code></pre>
 

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