Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this code not set the ui.datepicker.js calendar correctly when the date selects are set the first time?
    primarykey
    data
    text
    <p>I have a date input form which uses three selects (day/month/year)</p> <p>The following script allows the selects to be set using datepicker. Additionally once you have done this once, the selects can be changed and the change is reflected in datepicker.</p> <p>But if you set the selects first then click to open datepicker it doesn't pick up the change to the selects and highlight the correct date in datepicker. It only works if you use the datepicker first!</p> <p>Here's the JQuery:</p> <pre><code>$(document).ready(function() { $('.installDatePicker').append('&lt;img src="assets/images/ico-calendar.png" width="20" height="22" alt="Pick date" /&gt;&lt;div class="cal"/&gt;') $('.installDatePicker').each(function(i){ $(this).find('.cal').datepicker({ beforeShow: readSelected, onSelect: updateSelected, minDate: new Date(2010, 1 - 1, 1), maxDate: new Date(2012, 12 - 1, 31), }).hide(); }) $(this).find('img').click(function(){ $(this).parent().find('.cal').datepicker({ beforeShow: readSelected }).show() }) }); // Get values of select boxes and send to datepicker function readSelected() { return { setDate: $(this).parent().val( $(this).find('select:eq(1)').val() + '/' + $(this).find('select:eq(0)').val() + '/' + $(this).find('select:eq(2)').val()) } } // Set values of select boxes from datepicker function updateSelected(date) { $(this).parent().find('select:eq(1)').val(date.substring(0, 2)); $(this).parent().find('select:eq(0)').val(date.substring(3, 5)); $(this).parent().find('select:eq(2)').val(date.substring(6, 10)); $(this).hide(); } </code></pre> <p>and here's the structure of a single date control</p> <pre><code>&lt;fieldset id="firstChoiceDate" class="installDatePicker"&gt; &lt;select&gt; &lt;option value="01"&gt;1&lt;/option&gt; &lt;option value="02"&gt;2&lt;/option&gt; &lt;option value="03"&gt;3&lt;/option&gt; &lt;option value="04"&gt;4&lt;/option&gt; &lt;option value="05"&gt;5&lt;/option&gt; &lt;option value="06"&gt;6&lt;/option&gt; &lt;option value="07"&gt;7&lt;/option&gt; &lt;option value="08"&gt;8&lt;/option&gt; &lt;option value="09"&gt;9&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="11"&gt;11&lt;/option&gt; &lt;option value="12"&gt;12&lt;/option&gt; &lt;option value="13"&gt;13&lt;/option&gt; &lt;option value="14"&gt;14&lt;/option&gt; &lt;option value="15"&gt;15&lt;/option&gt; &lt;option value="16"&gt;16&lt;/option&gt; &lt;option value="17"&gt;17&lt;/option&gt; &lt;option value="18"&gt;18&lt;/option&gt; &lt;option value="19"&gt;19&lt;/option&gt; &lt;option value="20"&gt;20&lt;/option&gt; &lt;option value="21"&gt;21&lt;/option&gt; &lt;option value="22"&gt;22&lt;/option&gt; &lt;option value="23"&gt;23&lt;/option&gt; &lt;option value="24"&gt;24&lt;/option&gt; &lt;option value="25"&gt;25&lt;/option&gt; &lt;option value="26"&gt;26&lt;/option&gt; &lt;option value="27"&gt;27&lt;/option&gt; &lt;option value="28"&gt;28&lt;/option&gt; &lt;option value="29"&gt;29&lt;/option&gt; &lt;option value="30"&gt;30&lt;/option&gt; &lt;option value="31"&gt;31&lt;/option&gt; &lt;/select&gt; &lt;select&gt; &lt;option value="01"&gt;Jan&lt;/option&gt; &lt;option value="02"&gt;Feb&lt;/option&gt; &lt;option value="03"&gt;Mar&lt;/option&gt; &lt;option value="04"&gt;Apr&lt;/option&gt; &lt;option value="05"&gt;May&lt;/option&gt; &lt;option value="06"&gt;Jun&lt;/option&gt; &lt;option value="07"&gt;Jul&lt;/option&gt; &lt;option value="08"&gt;Aug&lt;/option&gt; &lt;option value="09"&gt;Sep&lt;/option&gt; &lt;option value="10"&gt;Oct&lt;/option&gt; &lt;option value="11"&gt;Nov&lt;/option&gt; &lt;option value="12"&gt;Dec&lt;/option&gt; &lt;/select&gt; &lt;select&gt; &lt;option value="2010"&gt;2010&lt;/option&gt; &lt;option value="2011"&gt;2011&lt;/option&gt; &lt;option value="2012"&gt;2012&lt;/option&gt; &lt;/select&gt; &lt;/fieldset&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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